这是我的路由器
App.Router.map(function(){
this.resource('courses');
this.resource('course', { path: '/courses/:course_id'}, function(){
});
});
在我的CoursesRoute中我有 -
actions: {
willTransition: function(transition) {
// how to access the intended transition or the intended model id
if(this.get('model.id') == 102) { // here model is not accessible
transition.abort();
}
// Since courses is a ArrayController I get all the courses inside this.get('controller.content')
// But how do I get the model ID of the selected course.
}
}
这用于课程模板
{{#link-to 'course' this class='thumbnail course'}}
答案 0 :(得分:2)
您应该能够找到上下文模型的ID,如下所示:
actions: {
willTransition: function(transition) {
var contexts = transition.intent.contexts; // array of all context models
var contextID = contexts[0].id; // if you only expect one model, this is its ID
if(contextID == 102) { // now you can use the ID for your condition
transition.abort();
}
}
}