我正在使用 Ember、Ember-data 和 Rails。
当我在车把视图中创建一个链接时,它会链接到 /clinic/undefined。我试图让 View 代码创建一个看起来像:http://localhost:3000/#/clinic/1
但看起来像:的链接http://localhost:3000/#/clinic/undefined
。
任何想法为什么以及如何解决它?
看法:
<a {{action showClinic content.clinic href=true}}>Click here</a>
路由器:
root: Ember.Route.extend({
showClinic: Ember.Route.transitionTo('clinic'),
showDoctor: Ember.Route.transitionTo('doctor'),
index: Ember.Route.extend({
route: '/',
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('main');
}
}),
clinic: Ember.Route.extend({
route: '/clinic/:clinic_id',
connectOutlets: function(router, clinic) {
router.get('applicationController').connectOutlet('clinic', clinic);
router.get('clinicController').connectOutlet('doctors', clinic.get('doctors'));
}
}),
doctor: Ember.Route.extend({
route: '/doctor/:doctor_id',
connectOutlets: function(router, doctor) {
router.get('applicationController').connectOutlet('doctor', doctor);
}
})
})
模型:
App.Doctor = DS.Model.extend({
name: DS.attr('string'),
clinic: DS.belongsTo('App.Clinic')
});
JSON:
{
doctor: {
id: 1,
clinic_id: 1,
name: "Dr. Who"
}
}