【问题标题】:Ember-Data Fixture AdapterEmber-Data 夹具适配器
【发布时间】:2012-09-12 11:16:55
【问题描述】:

夹具适配器有提交方法吗?它有什么作用? 据我了解,store.commit() 在与 REST 适配器一起使用时会调用 API。

我可以将isLoaded 属性与夹具适配器一起使用吗?

基本上,我的控制器中有 2 条记录,分别称为 xy,还有一个属性内容,其中包含许多 y 类型的记录。 咖啡代码如下:

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

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

当我调用anotherMethod 时,它会更新x 并在存储上运行提交,因此会调用someMethod。 我的实际应用程序运行良好,但在测试的情况下someMethod 会从内容和存储中删除记录yisLoadedcommit 不是用于夹具数据存储的吗?

【问题讨论】:

    标签: ember.js ember-data


    【解决方案1】:

    是的,有一个提交方法,可以通过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();
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-19
      • 2015-07-20
      • 1970-01-01
      相关资源
      最近更新 更多