【发布时间】:2013-05-27 10:19:28
【问题描述】:
我想在同一页面上呈现事件和约会。但是,当我使用 AppointmentController 中的 needs api 来访问 EventsController 时,我可以看到它返回 内的约会事件控制器内容属性' 检查时。但是,当我尝试使用包含 'appointments' 的返回内容来获取 appointments 时,它会失败。我正在使用 eventAppt = this.get('controllers.events').get('model'); 获取 AppintmentsController 中的事件内容,它获取内容和返回的内容将 'appointments' 作为其数据的一部分,但是当我尝试使用以下命令获取返回内容数据中的约会列表时:eventAppt.get('appointments'); this.set('content', myAppoint);,它总是失败,Cannot call method 'indexOf' of undefined。
App.AppointmentsController = Em.ArrayController.extend({
needs: ['events'],
appoint: function(){
console.log("this: ", this.toString());
var eventAppt = this.get('controllers.events').get('model');
//This returns the correct data that includes 'appointments'
console.log(eventAppt);
var myAppoint= eventAppt.get('appointments');
this.set('content', myAppoint);
//This fails with 'Cannot call method 'indexOf' of undefined'
console.log(this.get(myAppoint));
}
});
事件控制器
App.EventsController = Em.ArrayController.extend({
});
型号:
App.Event = DS.Model.extend({
title: DS.attr('string'),
start: DS.attr('date'),
allDay: DS.attr('boolean'),
appointments: DS.hasMany('App.Appointment')
});
有没有人知道为什么这不起作用。
【问题讨论】:
-
你
events的模特是什么模特?Controller、ObjectController或ArrayController? -
谢谢,它是一个ArrayController。我已将其粘贴在问题下方并添加了事件模型。
-
您是否尝试过检索
content属性而不是model?例如。var eventAppt = this.get('controllers.events').get('content');? -
是的,这就是我第一次尝试的方法,当它失败时,我决定尝试使用“模型”。谢谢。
标签: ember.js handlebars.js ember-router