本文介绍了Ember.js - 多个beforeModel钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 ember
路线中有多个 beforeModel
钩子有什么问题?
Is there anything wrong with having multiple beforeModel
hooks in an ember
route?
例如,如果我有一个 mixin
,添加一个 beforeModel
钩子,然后
For example, if I have a mixin
that adds a beforeModel
hook, and then another beforeModel
in the route I'm "mixing in to".
推荐答案
App.Foo = Ember.Mixin.create({
beforeModel: function(transition, queryParams){
console.log('foo');
}
})
App.IndexRoute = Ember.Route.extend(App.Foo,{
beforeModel: function(transition, queryParams){
console.log('bar');
},
model: function() {
return ['red', 'yellow', 'blue'];
}
});
如果你想,可以这样称呼。 _super(param1,param2 ...)从扩展类调用基本方法。
If you want though, you can call this._super(param1, param2...) from the extended class to call the base method.
App.IndexRoute = Ember.Route.extend(App.Foo,{
beforeModel: function(transition, queryParams){
this._super(transition, queryParams);
console.log('bar');
},
model: function() {
return ['red', 'yellow', 'blue'];
}
});
这篇关于Ember.js - 多个beforeModel钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!