[英]Ember-data with ajax call on a different server
I'm quite new with Ember and I wanted to use Ember-Data as mush as I could but I'm fetching data from an other server. 我对Ember不太熟悉,我想尽可能地使用Ember-Data,但是我正在从其他服务器上获取数据。
So far, I didn't use ember-data for anything unless for the user login information... I wanted to know if it was smart to fetch the information from the server and to save it in Ember-Data to use it straight after. 到目前为止,除非有用户登录信息,否则我什么都不会使用ember-data。我想知道从服务器获取信息并将其保存在Ember-Data中以在以后直接使用它是否明智。 。
Server data ==> Ember-Data ==> Display information on the app 服务器数据==>灰烬数据==>在应用程序上显示信息
And when I wanted to modify some information this goes like that : 当我想修改一些信息时,它像这样:
Information updated ==> Ember-Data ==> Server 信息更新==>灰烬数据==>服务器
Is this could be a good way to use ember-data with an ajax call ? 这是通过ajax调用使用ember-data的好方法吗? Or is there is any other proper method to do it ? 还是有其他适当的方法可以做到这一点?
I must say that for every call I've got a lot of data back, and I don't know if I should create every field in my model or if ember-data is doing it itself. 我必须说,对于每个调用,我都有很多数据返回,而且我不知道是否应该在模型中创建每个字段,还是ember-data本身在做。
Thanks for your help. 谢谢你的帮助。
[edit] After I reading your answer I tried to figure it out how to do it but its hard.. [编辑]在阅读您的回答后,我试图弄清楚该如何做,但是很难。
For example I have to send a GET request to my server like this : 例如,我必须像这样向我的服务器发送一个GET请求:
store.find('enquiries');
This should return me all of my enquiries on my server. 这应该返回我对服务器的所有查询。
But how the store build for it ? 但是商店如何建立呢?
Should I do just this in my store.js ? 我应该在store.js中执行此操作吗?
App.store = DS.Store.extend({
adapter: '-active-model'
})
App.Enquiries = DS.Model.extend({
});
In my Model I've put this : 在我的模型中,我输入了:
DS.ActiveModelAdapter.reopen({
host: 'http://localhost/'
});
I've tried to read the doc, but there is not much explanation about it :/ 我已经尝试阅读该文档,但是对此没有太多解释:/
Option 1: You can use ActiveModel 选项1:您可以使用ActiveModel
DS.ActiveModelAdapter.reopen({
host: 'http://api.your-api/v1'
});
and in your store 在你的商店里
App.Store = DS.Store.extend({
adapter: '-active-model'
});
Option 2: Rest Adapter 选项2:底座适配器
DS.RESTAdapter.reopen({
host: 'http://api.your-api/v1'
});
That's it, now all your request are going to be redirected to your new "host" 就是这样,现在您的所有请求都将被重定向到新的“主机”
Reference http://emberjs.com/guides/models/the-rest-adapter/ 参考http://emberjs.com/guides/models/the-rest-adapter/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.