2016-06-14 25 views
0

結束後,在父組件調用父函數,我有以下幾點:如何保證一個子組件Ember.run.later在灰燼

. 
. 
. 
recurringFunc: function(delay, index){ 
    . 
    . 
    . 
    if (someFlag){ 
    Ember.run.later(_this, function() { 
     _this.send('otherFunc',{index: index}); 
     _this.send('recurringFunc', delay, ++index); 
    }, delay); 
    } 
}, 


otherFunc: function(somePara){ 
    . 
    . 
    . 
} 

在父模板我有以下幾點:

. 
. 
. 
{{template-name someFlag=someFlag}} 
. 
. 
. 

然後在孩子componoent我有以下幾點:

input: function(){ 
    this.set('someFlag', false); 
    this.sendAction('otherFunc', {index: someVal}); 
} 

當如果從觸發的動作子組件,它成功地更改父項中的某個標誌。但是,代碼在執行從子進程發起的其他Func調用之前不會等待父進程中的最後一個迭代運行。

我有其他代碼,我已經縮寫,取決於Ember.run.later的最後一次迭代後運行otherFunc。

如何從子組件調用父組件函數並確保Ember.run.later在調用的子函數執行之前完成?

+0

這與異步等待有什麼關係?你甚至使用ES8?哪些函數返回承諾? – Bergi

+0

對不起。我認爲異步等待意味着別的東西。我將刪除該標籤。 – user2517182

回答

0

對於遇到此問題的任何人,這就是我所做的。

我做了delay屬性父組件和父組件更新otherFunc如下:

otherFunc: function(somePara){ 
    var currentDelay = this.get('delay'); 
    Ember.run.later(_this, function() { 
    . 
    . 
    . 
    . 
    }, currentDelay); 
} 

這將調用新的指令,最後延遲從recurringFunc結束後。