2
我想寫一個前端與ember.js和餘燼數據的REST服務。服務器返回數據(我確實看到這個使用提琴手),但我總是得到錯誤Unable to set property 'store' of undefined or null reference
。我的JS代碼:模型商店是undefined
window.Cube = Ember.Application.create({
LOG_TRANSITIONS: true,
LOG_TRANSITIONS_INTERNAL: true
});
var attr = DS.attr;
Cube.Subject = DS.Model.extend({
name: attr(),
change_date: attr(),
create_date: attr()
});
Cube.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'backend/v1/api',
host: 'http://localhost:58721'
});
Cube.Store = DS.Store.extend({
revision: 12,
url: "http://localhost:58721",
adapter: Cube.ApplicationAdapter
});
Cube.IndexRoute = Ember.Route.extend({
model: function (params) {
var store = this.get('store');
return store.findAll('Subject');
}
});
錯誤的餘燼,data.js來源:
modelFor: function(key) {
if (typeof key !== 'string') {
return key;
}
var factory = this.container.lookupFactory('model:'+key);
Ember.assert("No model was found for '" + key + "'", factory);
factory.store = this; // error here
factory.typeKey = key;
return factory;
}
據我瞭解燼,商店應自動設置,但它始終是零。
如何定義模型,使商店可用?我錯過了什麼?
更新1: 更新後的餘燼。現在我用下面的版本:
DEBUG: Ember : 1.1.0
DEBUG: Ember Data : 1.0.0-beta.3
DEBUG: Handlebars : 1.0.0
DEBUG: jQuery : 1.9.1
不,我在控制檯中以下錯誤:
No model was found for 'nextObject'
Error while loading route: TypeError: Unable to set property 'store' of undefined or null reference
仍然是同樣的錯誤。根據http://emberjs.com/guides/models/finding-all-records-of-a-type/您應該使用findAll來獲取所有記錄 – Sascha
您正在使用哪個版本的Ember數據?我剛剛注意到你的ED商店的構建是舊的 – Kingpin2k
它是1.0.0當我看着ember.js和最新的餘燼數據 – Sascha