我正在使用路由器和控制器,我需要在控制器上完成一些操作,这是我的模型代码
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 }); } }); } });
这是我的控制者
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')); } } });
从控制器我试图获取模型以获取一些信息并格式化它,并将其发送到视图但是this.model或this.get('model')总是返回null,我怎样才能成功访问来自控制器的模型?谢谢