2013-10-08 130 views
0

我有嵌套模式定义,如:设置控制器内容

AS.ExerciseRun = DS.Model.extend({ 
    'name' : DS.attr('string'), 
    'exercise' : DS.belongsTo('exercise') 
}); 

AS.Exercise = DS.Model.extend({ 
    'name'   : DS.attr('string'), 
    'engagement' : DS.belongsTo('engagement') 
}); 

AS.Engagement = DS.Model.extend({ 
    'name'   : DS.attr('string') 
}); 

,我需要在我的名为“AnalyticsRunsIndex”阵列控制器的一个使用“ExerciseRun”的模式。我将它添加到arrayController的needs属性中。我有点卡住了,因为我不知道如何通过AnalyticsRunsIndexRoute将数据加载到我的ExerciseRunController中。我的路线代码是:

AS.AnalyticsRunsIndexRoute = Ember.Route.extend({ 
    exerciseRunId: null, 
    model: function() { 
     ..... 

    }, 
    setupController: function (controller, model) { 
     this._super(controller, model); 
     controller.set('exerciseRunId', this.get('exerciseRunId')); 
     this.controllerFor('analyticsTemplates').set('model', controller.get('store').find('analyticsTemplate')); 


        //TRIED AND FAILED!!! 
        //this returns a rejected promise with error TypeError: payload[prop].map is not a function 
     //this.controllerFor('exerciseRun').set('model', controller.get('store').find('exerciseRun', {'id': this.get('exerciseRunId')})); 


     //controller.get('store').find('exerciseRun', {'id': this.get('exerciseRunId')}).then(function(data){ 
     // this.controllerFor('exerciseRun').set('content',data); 
     //}); 

     //controller.get('store').find('exerciseRun', {'id': this.get('exerciseRunId')}).then(function(data){ 
     // controller.get('store').pushPayload('exerciseRun', data); 
     // controller.set('exerciseRun',data); 
     //}); 


     //set exerciseRun details to the arrayController from any one record 
     /* 
     var store = controller.get('store'); 
     $.ajax({ 
      type: "GET", 
      url: AS.baseURL + "exerciseRuns", 
      data: {"id": this.get('exerciseRunId')}, 
      success: $.proxy(function (data) { 
       //controller.set('exerciseRunData', data); 
      }, this), 
      dataType: "JSON" 
     }); 
     */ 


    } 
}); 

如何将这些数据传送到适当的控制器?我试着简单地将属性设置为ArrayController的实例,但这也不起作用。任何帮助都感激不尽。感谢

回答

1

我想在你的setupController钩,你应该能够做这样的事情:

// Get the controller outside of the promise. 
// Inside the promise 'this' points to something different. 
var exerciseRunController = this.controllerFor('exerciseRun'); 
controller.get('store').find('exerciseRun', {'id': this.get('exerciseRunId')}).then(function(data){ 
    exerciseRunController.set('content',data); 
}); 
+0

啊,我会尽力的。谢谢。我也可以做的工作是删除我的数组控制器中的需求属性,然后在setupController中,我做到了: controller.set('exerciseRun',store.find('exerciseRun',exerciseRunId)); –