工作
如何从ember生成web服务调用?现在我使用简单的web api返回json数据,但需要连接web服务,这是与xml文件
如果你不打算使用Ember Data,你可以在Route
模型钩子中将XML转换为JS对象,像这样:
App.IndexRoute = Ember.Route.extend({
model: function(){
return $.get('/url-to-some-xml').then(function(xml){
//here is where you would convert your xml to a JS object
return parsedXml
})
}
});
你的模板就可以访问parsedXml
对象中的数据。
如果你正在使用Ember Data,那么你将在Serializers normalizePayload
钩子中将XML转换为JS对象。关于如何使用normalizePayload
钩子的详细信息,请参见fetch上的Ember数据序列化和POST上的反序列化。