Ember数据:如何在最近的Ember版本中指定REST适配器的使用?

cyc*_*arc 3 ember.js ember-data

我只想更改从夹具适配器获取数据到REST适配器.我在文档中找不到正确的语法...无论我尝试什么,都不会对REST接口执行JSON调用.

有人可以帮忙吗?

PS.当我只使用JQuery调用(return $.getJSON('http://localhost:3000/articles.json');)时,这是有效的,但如上所述,我想使用Ember REST适配器...

我的模特:

App.Article = DS.Model.extend({
  title: DS.attr('string'),
  author: DS.attr('string'),
  body: DS.attr('string')
});
Run Code Online (Sandbox Code Playgroud)

我的修复适配器:

App.Store = DS.Store.extend({
  revision: 12,
  adapter: 'DS.FixtureAdapter'
});
Run Code Online (Sandbox Code Playgroud)

我的REST适配器(不工作)

App.Store = DS.Store.extend({
  revision: 12,
  adapter: DS.RestAdapter.create({
    url: 'http://localhost:3000'
  })
});
Run Code Online (Sandbox Code Playgroud)

我的路线

App.ArticleRoute = Ember.Route.extend({
  model: function () {
    App.Article.find();
    //return $.getJSON('http://localhost:3000/articles.json');
  }

});
Run Code Online (Sandbox Code Playgroud)

int*_*xel 5

你有类名错了,需要DS.RESTAdapter代替DS.RestAdapter

试试这个:

App.Store = DS.Store.extend({
  revision: 12,
  adapter: DS.RESTAdapter.create({
    url: 'http://localhost:3000'
  })
});
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你.