2

フィクスチャアダプタのcommitメソッドはありますか?それは何をするためのものか?私の理解ではstore.commit()、RESTアダプターで使用するとAPI呼び出しが行われます。

isLoadedフィクスチャアダプタでプロパティを使用できますか?

基本的に、コントローラーにはxandという2つのレコードがyあり、プロパティコンテンツには多くのyタイプのレコードがあります。以下のコーヒーコード:

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

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

私がそれを呼び出すと、anotherMethodそれは更新xされ、ストアでコミットを実行するため、someMethod呼び出されます。私の実際のアプリケーションは正常に実行されますが、テストの場合、コンテンツからsomeMethodレコードが削除yされ、保存されます。それはフィクスチャデータストア用ではisLoadedありcommitませんか?

4

1 に答える 1

8

はい、commitメソッドがあり、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();
    }
});
于 2012-10-23T16:48:17.337 に答える