我正在尝试从一个REST API源中加载样本数据到我的emberjs应用程序中,但我面临两个问题:
模型名称总是复数形式,所以代码总是生成/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);
}
});