[英]Ember Data Adapter
I am trying to write an Ember-Data adapter for using the Rhom JavaScript ORM for my ember app. 我试图编写一个Ember-Data适配器,以将Rhom JavaScript ORM用于我的ember应用程序。 But I have no idea what the methods like 'find', createRecord, findAll, etc should return. 但是我不知道应该返回什么方法,例如'find',createRecord,findAll等。
Is there any reference I can follow. 有没有我可以参考的参考。 I really dont understand what happens in the RESTAdapter. 我真的不明白RESTAdapter中会发生什么。 I see that there is an Ajax call. 我看到有一个Ajax调用。
I am planning on using the 1.0 version of Ember Data and so I referred the Transition Readme file here https://github.com/emberjs/data/blob/master/TRANSITION.md and it says at one place: 我打算使用Ember Data的1.0版本,因此我在这里将Transition Readme文件引用到https://github.com/emberjs/data/blob/master/TRANSITION.md ,它在一个地方说:
App.MyAdapter = DS.Adapter.extend({
find: function(store, type, id) {
return $.getJSON("/" + this.pluralize(type) + "/" + id);
}
});
Does this mean I just can return whatever I want? 这是否意味着我可以退还我想要的一切? like JSON or something? 像JSON之类的东西?
And should I use Ember.RSVP.resolve()
at the end of the methods like in https://github.com/rpflorence/ember-localstorage-adapter/blob/master/localstorage_adapter.js . 而且我应该在https://github.com/rpflorence/ember-localstorage-adapter/blob/master/localstorage_adapter.js之类的方法的末尾使用Ember.RSVP.resolve()
。
"find", ideally, would return a promise, like in the basic Adapter example you saw there: 理想情况下,“ find”将返回一个承诺,就像您在此处看到的基本Adapter示例中一样:
App.MyAdapter = DS.Adapter.extend({
find: function(store, type, id) {
return $.getJSON("/" + this.pluralize(type) + "/" + id);
}
});
The 'getJSON' returns a promise, and Ember-data knows how to deal with it. “ getJSON”返回一个承诺,Ember数据知道如何处理它。
findQuery is similar, but the result of the promise should be an array. findQuery是相似的,但是promise的结果应该是一个数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.