2017-02-23 46 views
2

ExtJS MessageBox似乎不會像JavaScript警報(..)那樣阻止。我想顯示一個彈出窗口,然後調用和AJAX調用,然後關閉窗口。ExtJS MessageBox不會像塊警報(..)那樣阻止(..)

如果我這樣調用,則顯示方法......

//Alert Box : 
var alertBox = Ext.create('Ext.window.MessageBox'); 
var config = { 
    title : 'Title', 
    closable: true, 
    msg: 'Message', 
    buttons: Ext.Msg.OK, 
    buttonText: { ok: EML.lang.buttons.ok }, 
    modal: true 
}; 
alertBox.show(config); 


//callback 
Ext.Ajax.request({ 
    url: someURL, 
    method: 'POST', 
    callback: function (options, success, response) { 
     //do some stuff 
     self.up('window').destroy(); 
    } 
}) 

..no彈出所示,但是父窗口關閉。

如果我使用標準的Javascript 警報那麼警報將會阻止。點擊確定按鈕後,執行回調後窗口關閉。

//Alert Box : 
    alert('asdf') 


    //callback 
    Ext.Ajax.request({ 
     url: someURL, 
     method: 'POST', 
     callback: function (options, success, response) { 
      //do some stuff 
      self.up('window').destroy(); 
     } 
    }) 
  • 爲什麼MessageBox中沒有阻止?
  • 我能做些什麼來解決這個問題?
  • MessageBox以某種方式需要知道關於父窗口來阻止?

回答

4

它不會阻止,因爲自定義JavaScript代碼中不支持塊。正如Chrome控制檯告訴我們的,

window.alert 
function alert() { [native code] } 

和本地代碼可以阻止執行。

在ExtJS的,你會寫一個回調像這樣的消息框:

//Alert Box : 
var alertBox = Ext.create('Ext.window.MessageBox'); 
var config = { 
    title : 'Title', 
    closable: true, 
    msg: 'Message', 
    buttons: Ext.Msg.OK, 
    buttonText: { ok: EML.lang.buttons.ok }, 
    modal: true, 
    callback:function(btn) { 
     //callback 
     Ext.Ajax.request({ 
      url: someURL, 
      method: 'POST', 
      callback: function (options, success, response) { 
       //do some stuff 
       self.up('window').destroy(); 
      } 
     }) 
    } 
}; 
alertBox.show(config); 

如果這樣的回調深度嵌套,我趨向扁平化的回調是這樣的:

var store = me.down('grid').getStore(), 
    callback3 = function(btn) { 
     if(btn=="yes") store.sync(); 
    }, 
    callback2 = function() { 
     Ext.Msg.prompt('A','Third', callback3); 
    }, 
    callback1 = function() { 
     Ext.Msg.alert('A','Second', callback2); 
    }; 
Ext.Msg.alert('A','First', callback1); 

在更新版本的ExtJS,您可以查看Ext.Promise,但不能在ExtJS 4.1中查看。

+0

是的,我最終實現它是這樣的。它讀得不好。如果我有連續5個警告框的情況怎麼辦?在JavaScript中,我只需要5行警報(..)。在Extjs中,我需要在對方中嵌入5個消息框,看起來像一團糟...除非有承諾的方式 –

+0

@OliverWatkins我已經修改了我的答案。 – Alexander