Chr*_*let 17 javascript ember.js ember-router
我想要一个Ember路径/clinic/1
自动重定向以显示第一位医生:/clinic/1/doctor/1
.
每个诊所都有很多医生.
不幸的是,如果我使用此代码:
var doctor = clinicController.get('content.doctors.firstObject');
router.transitionTo('clinic.doctor.index', doctor);
Run Code Online (Sandbox Code Playgroud)
......这是行不通的,因为content.doctors.length
仍然是0
当这个代码运行app_router.js
.
有任何想法吗?
Yeh*_*atz 24
你应该能够做到这一点:
App.DoctorsRoute = Ember.Route.extend({
model: function() {
return App.Doctor.find();
},
redirect: function() {
var doctor = this.modelFor('doctors').get('firstObject');
this.transitionToRoute('doctor', doctor);
}
});
Run Code Online (Sandbox Code Playgroud)
这将有效,因为:
redirect
挂钩转换到另一个路径,则其余挂钩将不会运行.请注意,从2426cb9开始,您可以.index
在转换时省略隐含.
归档时间: |
|
查看次数: |
4279 次 |
最近记录: |