我的控制器中有一组对象。我可以显示属性,但未设置 linkTo 对象
我也使用 ember-model 而不是 ember-data
Msmapp.ClassroomsRoute = Ember.Route.extend({
model: function() {
return Msmapp.Classroom.findAll(); //Ember.Model
}
});
Msmapp.Classroom = Msmapp.Model.extend({
classroom_id: Ember.attr('number'),
classroom_name: Ember.attr('string'),
teacher_id: Ember.attr('number'),
grade: Ember.attr('number'),
students: Ember.attr('string'),
assignments: Ember.attr('string'),
classroomStudents: function () {
var studentObjects = []
this.get('students').forEach(function(student) {
studentObjects.push(Msmapp.Student.create(student));
});
return studentObjects;
}.property('students')
});
Msmapp.Classroom.reopenClass({
collectionKey: "classrooms",
url: '/classrooms'
});
{{#each classroom in controller }}
<li class="item">
{{#linkTo 'classroom' classroom }}{{ classroom.classroom_name }}{{/linkTo}}
</li>
{{/each}}
教室.classroom_name 工作得很好。我什至将其更改为计算属性。
但是链接没有设置模型。它是一个嵌套路由。
我得到/教室/未定义
奇怪的是,当我单击链接时,它会填充教室模型和视图。
我的路线
this.resource('classrooms', function() {
this.resource('classroom', {path: ':classroom_id'}, function() {
this.route('new_student');
});
this.route('new');
});
注意:如果我将 :classroom_id 更改为 :id 我会得到这样的东西
/classrooms/<Msmapp.Classroom:ember403>
我刚刚从 ember-data 切换到 ember-model,所以我确定它是微不足道的。