Ember.js - 多个 beforeModel 钩子 [英] Ember.js - Multiple beforeModel Hooks

查看:16
本文介绍了Ember.js - 多个 beforeModel 钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ember 路由中有多个 beforeModel 钩子有什么问题吗?

Is there anything wrong with having multiple beforeModel hooks in an ember route?

例如,如果我有一个 mixin,它添加了一个 beforeModel 钩子,然后在路由中添加了另一个 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".

推荐答案

不,如果你在路由和 mixin 上定义了它,路由将胜出.在下面的示例中,只会调用 bar.

No, if you have it defined on the route and mixin, the route will win out. In the example below, only bar will be called.

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'];
  }
});

http://emberjs.jsbin.com/runuowe/1/edit

如果你愿意,你可以从扩展类调用 this._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'];
  }
});

http://emberjs.jsbin.com/runuowe/4/edit

这篇关于Ember.js - 多个 beforeModel 钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆