用户可以通过表单域进行操作。但我不知道如何保存(提交)它们。当我更改lastName
aUser
并单击保存按钮时,我会收到以下错误:
Uncaught Error: Attempted to handle event `save` on <App.User:ember309:1> while in state rootState.loaded.updated.uncommitted. Called with undefined
通过单击保存按钮,我必须更改哪些内容才能保存(提交)记录?
索引.html
<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>
应用程序.js
App = Ember.Application.create();
App.Store = DS.Store.extend({
revision: 12,
adapter: 'DS.FixtureAdapter'
})
App.Router.map(function() {
this.resource('users', function() {
this.resource('user', { path: ':user_id' })
})
});
App.UsersRoute = Ember.Route.extend({
model: function() {
return App.User.find();
}
});
App.UserController = Ember.ObjectController.extend({
save: function() {
this.commit();
}
})
App.User = DS.Model.extend({
lastName: DS.attr('string')
})
App.User.FIXTURES = [{
id: 1,
lastName: "Smith"
}]