2017-05-02 29 views
0

我要聽所有模式隱藏事件usign引導標準事件:不能聽bootbox hidden.bs.modal事件

$(document).on("hidden.bs.modal",".modal",function(){ 
    ... 
}); 

我也需要使用此事件bootbox對話,但是這並未」工作。展望我發現bootbox源(行https://github.com/makeusabrew/bootbox/blob/master/bootbox.js 659):

dialog.one("hidden.bs.modal", function(e) { 
     // ensure we don't accidentally intercept hidden events triggered 
     // by children of the current dialog. We shouldn't anymore now BS 
     // namespaces its events; but still worth doing 
     if (e.target === this) { 
     dialog.remove(); 
     } 
}); 

如果因爲這破壞了調用對象本bootbox回調我的回調,我絕望之前調用。

可以繞過這個問題嗎?我如何能夠呼叫所有模態隱藏事件(也適用於Bootbox模式)?

回答

0

假設可以封裝...代碼,您可以爲每個Bootbox調用訂閱事件。喜歡的東西:

function doSomethingWhenModalCloses(){ 
    ... 
} 

bootbox 
    .alert('I am an alert!') 
    .on('hidden.bs.modal', doSomethingWhenModalCloses); // repeat for other functions 

這顯然不是最優的,但Bootbox並沒有真正提供了一個內置的方式委託從全球的那些事件。