我正在关注 this tutorial 并且任何时候它引用输入元素时它都将它们定义为:
{{input type="text action='actionname'... }}
有人告诉我这已经过时了,而且文档确实没有 use that format ,而不是使用这种格式:
<input type="text" {{action 'actionname' ... }}
我正处于将数据保存到商店的教程中。我修改了教程以使用尖括号而不是像这样的大括号:
<input type="text" value={{model.name}} class="form-control" placeholder="The name of the Library" />
<input type="text" value={{model.address}} class="form-control" placeholder="The address of the Library" />
<input type="text" value={{model.phone}} class="form-control" placeholder="The phone number of the Library" />
<button type="submit" class="btn btn-default" {{action 'saveLibrary' model}}>Add to library list</button>
我的路线是这样的:
import Route from '@ember/routing/route';
export default Route.extend({
model() {
return this.store.createRecord('library');
},
actions: {
saveLibrary(newLibrary) {
newLibrary.save().then(() => this.transitionTo('libraries'));
},
willTransition() {
this.controller.get('model').rollbackAttributes();
}
}
});
当我调用路由操作 saveLibrary
并打开调试器时,newLibrary
没有来自模型属性的任何数据。每当我像教程那样更改 Handlebars 模板以使用大括号时,它都可以正常工作; newLibrary 包含name
, address
& phone
.
使用 Angular 括号并将其传播到 route.js
的语法是什么?
最佳答案
尖括号组件应为 <Input>
不是<input>
.
关于javascript - 为 Handlebars 模板中的模型赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56689480/