簡體   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