gpt4 book ai didi

javascript - Ember js 在 willTransition 中转换为模型 id

转载 作者:行者123 更新时间:2023-11-30 17:12:14 25 4
gpt4 key购买 nike

这是我的路由器

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.
}
}

这是在类(class)模板中使用的

{{#link-to 'course' this class='thumbnail course'}}

最佳答案

您应该能够像这样找到上下文模型的 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();
}
}
}

关于javascript - Ember js 在 willTransition 中转换为模型 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26762759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com