无法使用 Ember 更改适配器主机

Can't change adapter host with Ember

我已经阅读了 Ember 文档,我知道我必须使用自定义 RESTAdapter 并将其设置为 App.Store。我做到了,它改变了命名空间,但是它不适用于主机(它仍然向当前域发出请求)。

App.ApplicationAdapter = DS.RESTAdapter.extend({
  host: 'https://api.example.com',
  namespace: 'kraken'
});

App.Store = DS.Store.extend({
  adapter: App.ApplicationAdapter
});


App.IndexRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('game');
  }
});

并且正在向当前域而不是 https://api.example.com

发出请求
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/kraken/games

使用最新的 Ember 数据 (1.0.0-beta.*),您无需指定商店。

只需指定适配器即可。

它的工作示例:

http://emberjs.jsbin.com/zemurayabi/1/edit?js,console,output

App = Ember.Application.create();

App.Router.map(function() {
  // put your routes here
});

App.ApplicationAdapter = DS.RESTAdapter.extend({
  host: 'https://api.example.com',
  namespace: 'kraken'
});

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('game');
  }
});

App.Game = DS.Model.extend({

});

请注意,由于 ajax 请求无处可去,它实际上会出错。但它会尝试正确的非本地 url.