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的實例,但這也不起作用。任何幫助都感激不盡。感謝
啊,我會盡力的。謝謝。我也可以做的工作是刪除我的數組控制器中的需求屬性,然後在setupController中,我做到了: controller.set('exerciseRun',store.find('exerciseRun',exerciseRunId)); –