【发布时间】:2013-12-14 16:12:36
【问题描述】:
我正在为一个项目评估 EmberJs,并完成 Tom Dale 的 ember 截屏视频。但我没有使用 Ember Data 并且正在尝试调整我们的内容(本示例中的 Post 对象)。
在 Ember Data 模型中,他使用 this.get('store').commit() 保存并持久化到服务器。我试图在我的 Post 模型上获取一个保存对象,并在用户单击应该触发 save 方法的按钮时调用它。我该怎么做?我尝试的是在底部(this.save、this.model.save、this.post.save),但包含了几乎所有的代码。另外,这种通用方法是否合理?
感谢帮助
window.Hex = Ember.Application.create();
Hex.Router.map(function() {
this.resource('posts', function(){
this.resource('post', { path: ':post_id' });
});
});
// the model class
Hex.Post = Ember.Object.extend({
save: function(){ a
console.log("you clicked save");
}
});
Hex.PostRoute = Ember.Route.extend({
model: function(params) {
return $.getJSON("/arc/v1/api/all-post", function(data){
var post = Hex.Post.create();
post.set('id', data.id);
return post;
});
}
});
Hex.PostController = Ember.ObjectController.extend({
isEditing: false,
actions:{
edit: function() {
this.set('isEditing', true);
console.log("within edit");
},
doneEditing: function() {
this.set('isEditing', false);
this.save(); // doesn't work trying to get a reference to the post object
this.model.save(); // doesn't work - undefined
this.post.save(); // doesn't work - undefined
//this.get('store').commit(); what is called in the sample app
}
}
});
【问题讨论】:
标签: ember.js