是否有用于fixture适配器的commit方法?是干什么的呢?据我所知,当与REST适配器一起使用时,store.commit()会发出一个API调用。
我可以在夹具适配器中使用isLoaded属性吗?
基本上,我的控制器中有两条记录,分别是x和y,还有一个属性内容,其中有许多y类型的记录。咖啡代码如下:
someMethod: (->
content.removeObject(y)
).('x.isLoaded')
anotherMethod: ->
//modify x
Application.store.commit()当我调用anotherMethod时,它会更新x并在存储上运行提交,因此会调用someMethod。我的实际应用程序运行得很好,但是在测试的情况下,someMethod会从内容和存储中删除记录y。是不是isLoaded和commit不适用于fixture数据存储?
发布于 2012-10-24 00:48:17
是的,有一个commit方法,可以通过DS.Store或DS.Transaction访问。
这里有一个fiddle,它有一些很好的代码,可以快速地演示带有fixture的CRUD。
window.App = Ember.Application.create();
App.store = DS.Store.create({
revision: 4,
adapter: 'DS.fixtureAdapter'
});
App.Person = DS.Model.extend({
id: DS.attr('number'),
name: DS.attr('string')
})
App.Person.FIXTURES = [
{id: 1, name: 'Fixture object 1'},
{id: 2, name: 'Fixture object 2'}
];
App.people = App.store.findAll(App.Person);
App.store.createRecord(App.Person, {id: 1, name: 'Created person'});
App.personView = Em.View.extend({
isVisibleBinding: 'notDeleted',
notDeleted: function() {
return !this.getPath('person.isDeleted');
}.property('person.isDeleted').cacheable(),
remove: function () {
this.get('person').deleteRecord();
}
});https://stackoverflow.com/questions/12386913
复制相似问题