ember.js - model returns null on controller -
i'm working a router , controller, , need complete operations on controller, model code
acornstest.stockroute = ember.route.extend({ model: function(params) { "use strict"; var url_params = params.slug.split('|'), url = acornstest.config.quandl.url + '/' + url_params[0] + '/' + url_params[1] + '.json', stockinstore = this.store.getbyid('stock', url_params[1]), today = new date(), yearago = new date(), self = this; yearago.setfullyear(today.getfullyear() - 1); today = today.getfullyear()+'-'+today.getmonth()+'-'+today.getdate(); yearago = yearago.getfullyear()+'-'+yearago.getmonth()+'-'+yearago.getdate(); if(stockinstore && stockinstore.get('data').length) { return stockinstore; } return ember.$.getjson(url,{ trim_start: yearago, trim_end: today, auth_token: acornstest.config.quandl.apikey }) .then(function(data) { if(stockinstore) { return stockinstore.set('data', data.data); } else { return self.store.createrecord('stock', { id: data.code, source_code: data.source_code, code: data.code, name: data.name, description: data.description, display_url: data.display_url, source_name: data.source_name, data: data.data, slug: data.source_code+'|'+data.code }); } }); } });
and controller
acornstest.stockcontroller = ember.objectcontroller.extend({ init: function() { "use strict"; this.send('generatechartinfo'); }, actions: { generatechartinfo: function() { "use strict"; console.log(this.model); console.log(this.get('model')); } } });
from controller i'm trying access model information , format it, , send view this.model or this.get('model') returns null, how can successful access model controller? thanks
you overriding init
method, broken, this:
acornstest.stockcontroller = ember.objectcontroller.extend({ init: function() { "use strict"; this._super(); this.send('generatechartinfo'); });
you need call parent method.
see test case: http://emberjs.jsbin.com/gijon/3/edit?js,console,output
the model not ready @ init
time. if has official docs please share.
Comments
Post a Comment