我的路线定义如下:
setupController: function (controller, model) {
var analyticsRuns,
store = this.get('store'),
exerciseRunId = this.controllerFor('analyticsContext').get('exerciseRunId');
// Query the server for all runs that belong to this exercise run.
// The results of the query will be loaded into the store so we can start
// filtering them, thus taking advantage of live updates.
// (see http://emberjs.com/guides/models/frequently-asked-questions/)
store.find('analyticsRun', { 'exerciseRunId': exerciseRunId });
analyticsRuns = store.filter('analyticsRun', function (analyticsRun) {
return analyticsRun.get('exerciseRunId') === exerciseRunId;
});
controller.set('model', analyticsRuns);
controller.set('exerciseRunId', exerciseRunId);
controller.set('analyticsTemplates', store.find('analyticsTemplate'));
controller.set('exerciseRun', store.find('exerciseRun',exerciseRunId));
controller.send('setAnalyticsRunSelectOptions');
}
在我的控制器操作中,“setAnalyticsRunSelectOptions”定义为:
setAnalyticsRunSelectOptions: function () {
var options = [], run;
//console.log(this.get('content'));
//console.log(this.get('content.length'));
//for(var i= 0,len=this.get('content.length');i<len;i++){
// run = this.get('content').objectAt(i);
// options.push({"id": run.get('id'), "label": run.get('id') + " " + run.get('name')});
//}
console.log(this.get('content'));
this.get('model').forEach(function (run) {
options.push({"id": run.get('id'), "label": run.get('id') + " " + run.get('name')});
});
this.set('analyticsRunSelectOptions',options);
}
但是当我在我的萤火虫中记录该功能中的“内容”时,它显示
{ 内容=[0],商店=,经理=,更多...}
但是当我点击它(在萤火虫中)时,可以在那里看到内容。我认为它是因为调用 setAnalyticsRunSelectOptions 时尚未填充内容。有没有办法仅在内容可用时触发我的操作?
谢谢,迪