伙计们!使用 ember-data 存储从远程服务器获取的跨域 ajax 请求的数据的任何示例?现在我有了这个,但是...
TravelClient.Tour = Ember.Object.extend({
});
TravelClient.Tour.reopenClass({
allTours: [],
find: function(){
$.ajax({
url: 'http://someIP:somePORT/tours.json',
dataType: 'jsonp',
context: this,
success: function(data){
data.forEach(function(tour){
this.allTours.addObject(TravelClient.Tour.create(tour))
}, this)
}
})
return this.allTours;
}
});
更新: 现在我这样做:
TravelClient.Tour.reopenClass({
allTours: [],
find: function(){
$.ajax({
url: 'http://someIP:somePORT/tours.json',
dataType: 'jsonp',
context: this,
success: function(response){
response.data.forEach(function(tour){
this.allTours.addObject(TravelClient.Tour.create(tour))
}, this)
}
})
return this.allTours;
}
});
但是得到这个错误:
Uncaught TypeError: Cannot call method 'forEach' of undefined
快照:
有了这个:
$.ajax({
dataType: 'jsonp',
url:"http://192.168.1.39:3000/tours.json",
success:function(response){
return response.data;
}
});
我明白了:
Object
abort: function (e){var t=e||S;return r&&r.abort(t),N(0,t),this}
always: function (){return i.done(arguments).fail(arguments),this}
complete: function (){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
done: function (){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
error: function (){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
fail: function (){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
getAllResponseHeaders: function (){return E===2?s:null}
getResponseHeader: function (e){var t;if(E===2){if(!o){o={};while(t=wn.exec(s))o[t[1].toLowerCase()]=t[2]}t=o[e.toLowerCase()]}return t==null?null:t}
overrideMimeType: function (e){return E||(c.mimeType=e),this}
pipe: function (){var e=arguments;return y.Deferred(function(n){y.each(t,function(t,s){var o=s[0],u=y.isFunction(e[t])&&e[t];i[s[1]](function(){var e=u&&u.apply(this,arguments);e&&y.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[o+"With"](this===r?n.promise():this,u?[e]:arguments)})}),e=null}).promise()}
progress: function (){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
promise: function (e){return e!=null?y.extend(e,r):r}
readyState: 4
setRequestHeader: function (e,t){var n=e.toLowerCase();return E||(e=b[n]=b[n]||e,g[e]=t),this}
state: function (){return n}
status: 200
statusCode: function (e){var t;if(e)if(E<2)for(t in e)m[t]=[m[t],e[t]];else x.always(e[x.status]);return this}
statusText: "success"
success: function (){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
then: function (){var e=arguments;return y.Deferred(function(n){y.each(t,function(t,s){var o=s[0],u=y.isFunction(e[t])&&e[t];i[s[1]](function(){var e=u&&u.apply(this,arguments);e&&y.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[o+"With"](this===r?n.promise():this,u?[e]:arguments)})}),e=null}).promise()}
__proto__: Object