Ember数据夹具适配器

ine*_*tia 2 ember.js ember-data

是否有夹具适配器的提交方法?它有什么作用?据我所知,store.commit()当与REST适配器一起使用时会发出API调用.

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

基本上我有2个记录在我的控制器名为xy和具有的许多记录的属性内容y类型.咖啡代码如下:

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

anotherMethod: ->
  //modify x
  Application.store.commit()
Run Code Online (Sandbox Code Playgroud)

当我调用anotherMethod它更新x并在商店上运行提交时,因此someMethod被调用.我的实际应用程序运行正常,但如果测试从内容和商店中someMethod删除记录y.难道是isLoadedcommit不是为固定数据存储?

小智 8

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

这是一个小提琴,有一些很好的代码,可以用夹具快速演示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();
    }
});
Run Code Online (Sandbox Code Playgroud)