Ember数据夹具适配器 [英] Ember-Data Fixture Adapter
问题描述
夹具适配器有提交方法吗?它有什么作用?
由于我的理解是 store.commit()
在与REST适配器一起使用时调用API调用。
我可以用夹具适配器使用 isLoaded
属性吗?
基本上我的控制器中有2条记录称为 x
和 y
和具有许多 y
类型记录的属性内容。
以下的咖啡代码:
someMethod:( - >
content .removeObject(y)
)。('x.isLoaded')
anotherMethod: - >
//修改x
Application.store.commit()
当我调用 anotherMethod
它更新 x
并在存储上运行提交,因此 someMethod
被调用。
我的实际应用程序运行正常,但是如果测试 someMethod
从内容中删除记录 y
商店。
是否这个 isLoaded
和 commit
不是用于夹具数据存储?
这是一个小提琴有一些很好的代码,可以快速演示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对象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('
} .property('person.isDeleted')。cacheable(),
remove:function(){
this.get('person' ).deleteRecord();
}
});
Is there a commit method for the fixture adapter? What does it do?
As my understanding goes store.commit()
puts an API call when used with REST adapter.
Can I use isLoaded
property with fixture adapter?
Basically I have 2 records in my controller called x
and y
and a property content that has many records of y
type.
Coffee code below:
someMethod: (->
content.removeObject(y)
).('x.isLoaded')
anotherMethod: ->
//modify x
Application.store.commit()
When I call anotherMethod
it updates x
and runs a commit on store, hence someMethod
gets called.
My actual application runs fine but in case of tests someMethod
removes the record y
from content as well as store.
Is it that isLoaded
and commit
are not for fixture data store?
Yes, there is a commit method and it is accessible through DS.Store or DS.Transaction.
Here's a fiddle that has some good code that quickly demonstrates CRUD with fixtures.
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();
}
});
这篇关于Ember数据夹具适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!