繁体   English   中英

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

[英]How can I bubble up an Ember action inside a callback function?

我有一个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;
            }
        }
    }
});

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

我错过了什么?

您可以通过调用self.target.send('myAction');手动触发气泡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);
    }
  }
});

会冒泡到像这样定义的ApplicationRoute

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM