When you provide a model in themodelhook
of a route ember converts the raw array (users) into an ember array that provides observation and convenience methods likepushObject
.
是针对这行代码的解释:
var user = users.pushObject({id: users.length}); //创建一个新用户
完整代码段:
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return users;
},
events: {
createUser: function() {
var users = this.modelFor('application'); // 定义数据来源于 application 数据模型
var user = users.pushObject({id: users.length}); //创建一个新用户
this.transitionTo('editUser', user); // 转向 editUser 页面
}
}
});