如何将 JSONP 数据类型与 Ember Data 一起使用? [英] How do I use the JSONP datatype with Ember Data?

查看:21
本文介绍了如何将 JSONP 数据类型与 Ember Data 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置 Ember Data 在进行 ajax 调用时使用 JSONP 数据类型?我将在 Phonegap 中使用 Ember,并且需要进行跨域请求.

How do I set up Ember Data to use the JSONP datatype when making its ajax calls? I am going to be using Ember with Phonegap and need to make cross-domain requests.

推荐答案

您需要创建自己的使用 jsonp 的适配器,您可以通过扩展当前的适配器来实现,看看.

You need to create your own adapter which uses jsonp, you can do just that by extending a current one, have a look.

App.MyAdapter= DS.RESTAdapter.extend({})

然后你需要实现find方法等等,使用jsonp,可能是这样的

Then you need to implement the find method among others, to use jsonp, could be something like this

App.MyAdapter= DS.RESTAdapter.extend({
  find: function(store, type, id) {
     var item;
     $.ajax({
      url: 'http://api.domain/someModel',
      dataType: 'jsonp',
      success: function(response){
        item = App.someModel.create(order))
      }
    });
    return item;
  },

这没有经过测试,但它应该让您知道如何完成我的工作.:)

This is not tested, but it should give you the idea of how i can be done. :)

这篇关于如何将 JSONP 数据类型与 Ember Data 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆