如何在回调函数中冒泡Ember动作?

Mic*_*nch 5 controller return callback event-propagation ember.js

我有一个Ember应用程序,我正在使用一个动作来应用CSS动画.一旦动画完成,我想将操作从控制器冒泡到我的路线以处理更多功能.

我知道如果我return: true;的动作会冒出来,就像这里所解释的那样.

这就是我的控制器的样子:

App.MyController = Ember.ObjectController.extend({
    actions: {
        myAction: function() {
            $('.my-element').addClass('my-animation-class').one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e) {
                console.log('working');
                return true;
            }
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

如果我在animationend回调中将某些内容记录到我的控制台,我可以看到它正常工作,如果我移出return: true;回调,则该动作会成功冒泡.但是,在回调内部返回true是行不通的.

我错过了什么?

tik*_*zky 8

您可以通过调用手动触发气泡 self.target.send('myAction');

一个IndexController这样定义

App.IndexController = Ember.Controller.extend({
  actions: {
    bubbleMe: function(item){
      var self = this;
      alert('IndexController says you clicked on: ' + item);
      setTimeout(function(){
        self.target.send('bubbleMe',[item]);
      }, 1000);
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

会冒泡到ApplicationRoute像这样的定义

App.ApplicationRoute = Ember.Route.extend({
  actions: {
    bubbleMe: function(item){
      alert('ApplicationRoute says you clicked on: ' + item);
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

你可以在这里看到一个工作小提琴:http://jsfiddle.net/tikotzky/2ce9s32f/