【发布时间】:2014-02-17 14:06:58
【问题描述】:
我正在尝试从 REST API source 加载示例数据,该 API 在我的 emberjs 应用程序中返回 XML,但我面临两个问题:
模型名称始终为复数形式,因此代码始终生成 /sqlrest/CUSTOMERS/3/ 而不是 /sqlrest/CUSTOMER/3/
我知道 DS.RESTAdaptor 在默认情况下需要 JSON 格式,所以我想知道有什么方法我仍然可以获得 XML 格式并可以转换为 JSON?
谢谢
我使用的代码如下(我在其中一个 SO 回复中找到并更改以匹配我尝试访问的 URL):
App.store = DS.Store.create({
revision: 11,
adapter: DS.RESTAdapter.create({
namespace: "sqlrest",
url: "http://www.thomas-bayer.com",
plurals: {
'customer': 'customer'
},
ajax: function (url, type, hash) {
hash.url = url;
hash.type = type;
hash.dataType = 'jsonp';
hash.contentType = 'application/json; charset=utf-8';
hash.context = this;
if (hash.data && type !== 'GET') {
hash.data = JSON.stringify(hash.data);
}
jQuery.ajax(hash);
},
})
});
在路线中:
App.CustomersRoute = Ember.Route.extend({
model: function() {
//return App.Customer.find();
//New
return App.Customer.find(18);
}
});
【问题讨论】:
标签: ajax rest ember.js ember-data