dimanche 21 décembre 2014

Ember Not Initializing Store Properly: Cannot read property 'find' of undefined

All my versions:



Ember: 1.9.0
Handlebars: 2.0.0
jQuery: 2.1.3
Ember Data: 1.0.0-beta.12


All I'm trying to do is make a simple Ember Data store.find() call and everything seems to be going horribly wrong. It gets even weirder too. If I wrap this.store.find(...) in a get() call and instead say this.get('store').find(...) I get a completely different error.


Here's the error I'm getting with just this.store.find(...):



Error while processing route: budget Cannot read property 'find' of undefined TypeError: Cannot read property 'find' of undefined
at Application.BudgetRoute.Ember.Route.extend.model (http://localhost/javascript/app/routes/budget.route.js:9:24)
at EmberObject.extend.deserialize (http://localhost/javascript/bower_components/ember/ember.js:24849:21)
at applyHook (http://localhost/javascript/bower_components/ember/ember.js:47575:30)
at Object.HandlerInfo.runSharedModelHook (http://localhost/javascript/bower_components/ember/ember.js:45596:22)
at Object.subclass.getModel (http://localhost/javascript/bower_components/ember/ember.js:45822:21)
at __exports__.bind (http://localhost/javascript/bower_components/ember/ember.js:47449:19)
at tryCatch (http://localhost/javascript/bower_components/ember/ember.js:47898:16)
at invokeCallback (http://localhost/javascript/bower_components/ember/ember.js:47910:17)
at publish (http://localhost/javascript/bower_components/ember/ember.js:47881:11)
at http://localhost/javascript/bower_components/ember/ember.js:29453:9


this.store is undefined here.


Here's the error I'm getting with this.get('store').find(...):



Error while processing route: budget Assertion Failed: Budget has no method `find`. Error: Assertion Failed: Budget has no method `find`.
at new Error (native)
at Error.EmberError (http://localhost/javascript/bower_components/ember/ember.js:13740:23)
at Object.Ember.assert (http://localhost/javascript/bower_components/ember/ember.js:3902:15)
at Object.EmberObject.extend.store.computed.find (http://localhost/javascript/bower_components/ember/ember.js:24892:19)
at Application.BudgetRoute.Ember.Route.extend.model (http://localhost/javascript/app/routes/budget.route.js:9:32)
at EmberObject.extend.deserialize (http://localhost/javascript/bower_components/ember/ember.js:24849:21)
at applyHook (http://localhost/javascript/bower_components/ember/ember.js:47575:30)
at Object.HandlerInfo.runSharedModelHook (http://localhost/javascript/bower_components/ember/ember.js:45596:22)
at Object.subclass.getModel (http://localhost/javascript/bower_components/ember/ember.js:45822:21)
at __exports__.bind (http://localhost/javascript/bower_components/ember/ember.js:47449:19)


This time it finds this.store, but the Budget model has no find() method on it (and no where on the internet are there instructions that say there should be...)


budget.route.js:



define([
'ember',
'application',
'controllers/budget.controller',
'views/budget.view'
], function(Ember, Application) {
Application.BudgetRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('budget', params.budget_key);
}
});

return Application.BudgetRoute;
});


My Budget model:



define([
'ember-data',
'application'
], function(DS, Application) {
Application.Budget = DS.Model.extend({
budget_key: DS.attr(),
user: DS.attr(),
title: DS.attr(),
description: DS.attr(),
picture: DS.attr(),
order: DS.attr(),
created: DS.attr()
});

return Application.Budget;
});


My ApplicationAdapter:



define([
'ember-data',
'application',
'models/budget'
], function(DS, Application) {
Application.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'api'
});

return Application.ApplicationAdapter;
});


I'm also using deferReadiness() and advanceReadiness() if that makes any difference here...





Aucun commentaire:

Enregistrer un commentaire