Friday, 15 February 2013

ember.js - Ember-Data "TypeError: this.container is undefined" -



ember.js - Ember-Data "TypeError: this.container is undefined" -

i'm trying load current user info store having difficulty. server uses passportjs , visiting /api/users/me returns json object similar this:

{"user":{"_id":"53a4d9c4b18d19631d766980","email":"ashtonwar@gmail.com", "last_name":"war","first_name":"ashton","location":"reading, england", "birthday":"12/24/1993","gender":"male","fb_id":"615454635195582","__v":0}}

my store defined app.store = ds.store.create();

the controller retrieve current user is:

app.userscurrentcontroller = ember.objectcontroller.extend({ content: null, retrievecurrentuser: function() { var controller = this; ember.$.getjson('api/users/me', function(data) { app.store.createrecord('user', data.user); var currentuser = app.store.find(data.user._id); controller.set('content', currentuser); }); }.call() });

it called application controller:

app.applicationcontroller = ember.controller.extend({ needs: "userscurrent", user: ember.computed.alias("controllers.userscurrent") });

i suspect line app.store.createrecord('user', data.user); causing issues don't have thought how prepare it.

the console logs typeerror: this.container undefined while ember debugger shows every promise fulfilled , users.current controller has no content. thankyou help can provide.

are defining store on app namespace, because ember info doesn't default. either way, you're failing define type want find after create record.

var currentuser = controller.store.find('user', data.user._id);

createrecord returns record, there no point in finding afterward

var currentuser = controller.store.createrecord('user', data.user);

also in example, trying phone call function on type, , not on instance. should add together method run on init.

app.userscurrentcontroller = ember.objectcontroller.extend({ retrievecurrentuser: function() { console.log('hello') var controller = this; ember.$.getjson('api/users/me', function(data) { var user = controller.store.createrecord('user', data.user); controller.set('model', user); }); }.on('init') });

http://emberjs.jsbin.com/oxidivu/693/edit

ember.js controller ember-data containers store

No comments:

Post a Comment