0

我正在使用 Ember CLI 并成功集成了 Simple Auth Addon。不幸的是,我目前面临一个问题,我似乎无法触发sessionAuthenticationFailed我的项目中的操作。ApplicationRoute我已经使用 Ember Simple Auth 的浏览器化版本成功地做到了这一点,但我现在真的很想使用 Ember CLI 的插件并弄清楚这一点!目前我ApplicationRoute在 Coffescript 中的样子是这样的:

`import Ember from 'ember'`
`import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin'`
`import Session from 'simple-auth/session'`

ApplicationRoute = Ember.Route.extend ApplicationRouteMixin,
  actions:
    sessionAuthenticationFailed: (error) ->
      debugger

`export default ApplicationRoute`

我还尝试重新打开 ApplicationRouteMixin 并debugger在函数中设置 a ,这也不起作用。据我所知,Ember Simple Auth 的源代码通过调用其函数Session来触发事件。我还将工作版本与目前不工作的版本进行了比较,当我在调用触发器后单步执行代码时,我最终进入了接收对象的函数,在这种情况下它是 Ember Simple Auth ,一个 eventName ,参数和动作。这里有趣的是,在这部分代码中从 Session 中读取了一些关于 listeners 的元数据:_this.trigger('sessionAuthenticationFailed', error)authenticatesendEventSession

var meta = obj[META_KEY];
actions = meta && meta.listeners && meta.listeners[eventName];

在我的情况下meta.listeners[eventName]undefined这意味着事件没有监听器sessionAuthenticationFailed,因此没有任何东西被调用,我最终没有用我的动作捕捉到事件。

现在最大的问题当然是为什么它似乎没有为此事件注册任何侦听器。是否有其他人已经在使用 Ember CLI Simple Auth Addon 并成功连接了该sessionAuthenticationFailed事件?如果有帮助,将不胜感激!

干杯,戴夫!

编辑 通过阅读源代码的评论,我看到如果在扩展 ApplicationRoute 中使用了 beforeModel 钩子,我也必须通过 this._super() 调用父级的 beforeModel 函数。我想我离解决这个问题又近了一步!

4

1 回答 1

1

好的,我解决了这个问题。所以我实现了我的beforeModel(transition)钩子ApplicationRoute来加载翻译,但没有用this._super(transition). 如果您遇到与我描述的相同的问题,这可能是它无法正常工作的原因之一!

于 2014-07-06T18:49:39.127 回答