2012-09-12 66 views
2

夹具适配器是否有提交方法?它有什么作用? 根据我的理解,store.commit()在与REST适配器一起使用时会放入API调用。灰烬数据夹具适配器

我可以用夹具适配器使用isLoaded属性吗?

基本上我有2个记录在我的叫xy控制器和具有y型的多条记录的属性内容。下面 咖啡代码:

someMethod: (-> 
    content.removeObject(y) 
).('x.isLoaded') 

anotherMethod: -> 
    //modify x 
    Application.store.commit() 

当我打电话anotherMethod它更新x和运行提交在商店,因此someMethod被调用。 我的实际应用运行正常,但在测试的情况下someMethod从内容和商店中删除记录y。 是否isLoadedcommit不适用于夹具数据存储?

回答

8

是的,有一个提交方法,它可以通过DS.Store或DS.Transaction访问。

这里有一个fiddle,它有一些很好的代码,可以快速显示带有灯具的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(); 
    } 
});