使用Ember Data,你如何调用commit? [英] with Ember Data, how do you call commit?
问题描述
我正在尝试使用所有最后的路线和数据填充垃圾来构建一个简单的Todo列表。您可以找到我的完整的回购 here
I am trying to build a simple Todo List using all the last routes and data stuff for ember. You can find my full repo here
我有我的商店设置如下:
I have my store set up like so:
EmberTodo.Store = DS.Store.extend({
revision: 11,
adapter: DS.RESTAdapter.create({bulkCommit: false})
});
给我麻烦的代码行来自于:
The line of code that is giving me trouble comes from here:
EmberTodo.CreateItemView = Ember.TextField.extend({
insertNewline: function() {
EmberTodo.Item.createRecord({description: this.get('value')});
this.set("value", "");
}
});
根据我的理解,调用 createRecord
不要创建记录,而是需要在某个地方调用 commit()
。但是,我无法弄明白哪里。任何人都有什么想法?
From what I understand, calling createRecord
doesn't create the record, but instead I need to call commit()
somewhere. However, I cannot figure out where. Anyone have any ideas?
推荐答案
根据我的理解,调用createRecord不会创建记录,在某处调用commit()但是,我无法弄明白哪里。任何人都有任何想法?
From what I understand, calling createRecord doesn't create the record, but instead I need to call commit() somewhere. However, I cannot figure out where. Anyone have any ideas?
当然可以。为了使这个工作尽可能小的
Sure. To get this working with the smallest possible
EmberTodo.CreateItemView = Ember.TextField.extend({
insertNewline: function() {
item = EmberTodo.Item.createRecord({description: this.get('value')});
item.get('transaction').commit();
this.set("value", "");
}
});
我已经使用DS.FixtureAdapter放置了一个简化的工作示例: http://jsbin.com/ugipap/1/edit
I've placed a simplified, working example using DS.FixtureAdapter here: http://jsbin.com/ugipap/1/edit
完成,对吗?
Done, right?
Kinda。事实上,你真的不希望从一个角度来做这样的事情。考虑重构将逻辑转移到控制器层,或者可能根据情况将路由器移动。
Kinda. Thing is, you really don't want to be doing this kinda thing from within a view. Consider refactoring to move this logic into the controller layer, or possibly the router depending on the situation.
这篇关于使用Ember Data,你如何调用commit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!