(emberJS) - 在RESTAdaper JSON数据上使用find时的TypeError

时间:2013-10-04 08:31:20

标签: json ember.js

我是embers JS的新手,并试图找出如何将数据从JSON API放到我的模型中。所以我有:

App.Store = DS.Store.extend({
revision: 12,
adapter : DS.RESTAdapter.create({
 url : 'http://eu.battle.net/api/d3/profile/Alucard-2129/?callback=?'
 }) });

App.Profiles = DS.Model.extend({
name: DS.attr("string"),
lastUpdated: DS.attr("string")});


App.ProfilesRoute = Ember.Route.extend({
model: function () {        
    return App.Profiles.find();
}});

但它根本不起作用......我得到错误:

Uncaught TypeError: Object function () { ... } has no method 'find' 

请帮忙......

2 个答案:

答案 0 :(得分:1)

由于Ember是一种新的东西,它变化很大。如果您下载最新的Ember版本和Ember Data beta插件的副本,您可以这样做:

App.ApplicationAdapter = DS.RESTAdapter.extend({
  host: 'http://eu.battle.net/api/d3/profile/Alucard-2129/?callback=?'
});

App.Profiles = DS.Model.extend({
name: DS.attr("string"),
lastUpdated: DS.attr("string")});

App.ProfilesRoute = Ember.Route.extend({
  model: function() {
    return this.store.find("profile");
  }
});

您在网上找到的所有帮助,已经过时了。至少,这就是我的经历。此页面列出了许多可能会派上用场的更改:https://github.com/emberjs/data/blob/master/TRANSITION.md#host-and-namespace-configuration

祝你好运;)

答案 1 :(得分:0)

您正在使用ember-data版本1.0.0-beta。而且您的代码来自旧版本。现在,您需要使用App.Profiles.find();而不是store.find('profiles');

描述了从旧版本到1.0.0-beta的过渡的完整描述here

App.ApplicationAdapter = DS.RESTAdapter.extend({
  host: 'http://eu.battle.net/api/d3/profile/Alucard-2129/?callback=?'
});

App.Profiles = DS.Model.extend({
  name: DS.attr("string"),
  lastUpdated: DS.attr("string")
});

App.ProfilesRoute = Ember.Route.extend({
  model: function() {
    return this.store.find("profiles");
  }
});

我希望它有所帮助