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 的需求属性中。我现在有点卡住了,因为我不确定如何通过 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 的实例,但这也不起作用。任何帮助都感激不尽。谢谢

4

1 回答 1

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);
});
于 2013-10-10T01:46:24.937 回答