2013-10-04 26 views
0

我是新來的emberJS,並試圖找出如何將數據從JSON API傳輸到我的模型。所以,我有:(emberJS) - 使用RESTAdaper JSON數據查找TypeError

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' 

請幫助...

回答

1

由於灰燼是一種新的,它變化很大。如果你下載最新的灰燼構建和灰燼數據測試版插件的副本,你可以這樣說:

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

祝你好運;)

+0

可惜的是我得到的錯誤是這樣的:遺漏的類型錯誤:無法讀取未定義的屬性'typeKey' – Alucard140488

0

Probally您正在使用的餘燼數據版本1.0.0-beta。而你的代碼來自舊版本。現在,而不是App.Profiles.find();您需要使用store.find('profiles');

從舊版本過渡的完整描述到1.0.0-β描述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"); 
    } 
}); 

我希望它能幫助