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

查看:86
本文介绍了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'];
  }
});

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

如果你想,可以这样称呼。 _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/runufowe/4/edit

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

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