简体   繁体   English

如何从ember调用Web服务

[英]How to call webservice from ember

How can i produce web service call from ember. 我如何从ember产生Web服务调用。 now I'm using simple web api which returns json data, but need to connect web service, which is working with xml file 现在我正在使用返回json数据的简单Web API,但是需要连接正在使用xml文件的Web服务

If you dont plan on using Ember Data you can just convert the XML to a JS object in the Route s model hook, like this: 如果您不打算使用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
    })
  }
});

your template would then have access to the data in the parsedXml object. 您的模板将可以访问parsedXml对象中的数据。

If you are using Ember Data then you would convert the XML to a JS object in a Serializers normalizePayload hook. 如果使用的是Ember Data,则可以在Serializers normalizePayload挂钩中将XML转换为JS对象。 see Ember Data serialize on fetch and deserialize on POST for details on how to use the normalizePayload hook. 有关如何使用normalizePayload挂钩的详细信息,请参见Ember数据在获取时序列化和在POST上反序列 normalizePayload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM