可以通过表单字段操作用户。但我无法弄清楚如何保存(提交)它们。如果我更改lastName
的{{1}}并单击保存按钮,我将收到以下错误:
User
点击保存按钮,我需要更改哪些保存(提交)记录?
的index.html
Uncaught Error: Attempted to handle event `save` on <App.User:ember309:1> while in state rootState.loaded.updated.uncommitted. Called with undefined
app.js
<script type="text/x-handlebars" data-template-name="users">
<table class='table'>
{{#each model}}
<tr>
<td>{{view Ember.TextField valueBinding='lastName'}}</td>
{{#with this as model}}
<td><button {{bindAttr class=":btn isDirty:btn-primary:disabled"}} {{action "save" target="model"}}>save</button></td>
{{/with}}
</tr>
{{/each}}
</table>
</script>
答案 0 :(得分:1)
您可以像这样更改代码
<script type="text/x-handlebars" data-template-name="users">
<table class='table'>
{{#each model in controller}}
<tr>
<td>{{view Ember.TextField valueBinding='lastName'}}</td>
<td><button {{bindAttr class=":btn isDirty:btn-primary:disabled"}} {{action "save"}}>save</button></td>
</tr>
{{/each}}
</table>
</script>
使用each model in controller
而非#with this as model
然后定义itemController
App.UsersController = Ember.ArrayController.extend({
itemController: 'user'
});
这样您就可以使用save
调用的UserController
方法。
最后,请确保保存记录:
App.UserController = Ember.ObjectController.extend({
save: function() {
this.get('content.transaction').commit();
}
})