4

ExtJS 4でwindow.confirmをオーバーライドしようとしています。オーバーライドはtrueまたはfalseのいずれかを返す必要があります(confirmと同じですが、優れたUIを使用します)。

window.confirm=function(msg) {var val=Ext.create("Ext.Window",{
    title : 'Extra window!',
    width : 150,                            
    height: 100,
    closable : true,                           
    html : msg,                         
    modal : true,
    onEsc:aa,
    items:[
           {
               xtype:'button',
               text:'Ok',
               handler:function()
               {
                   return true;
               }
           },
           {
               xtype:'button',
               text:'Cancel',
               handler:function(){
                   return false;
               }
           }
           ]
}).show();
function aa(btn)
{
    return false;
}

確認を使用するとモーダルウィンドウが表示されますが、trueまたはfalseのいずれも返されず、非同期で実行されます。

確認する代わりにshowModalDialogを試してみましたが、今回も戻り値が得られません。

ユーザーの選択に基づいてtrueまたはfalseを返すことは可能ですか(ユーザーが[OK]を選択した場合はtrueを返し、[キャンセル]をクリックした場合はfalseを返します)

4

1 に答える 1

4

同期方式でモーダル ダイアログを呼び出すことはできません。アプリケーションのさまざまな場所から呼び出すユーティリティ関数にラップしたい場合は、次のようにする必要があります。

showConfirmationDialog: function(question, yesCallback) {
    //... Create you window
    //... Show window - add handler to the YES button and call yesCallback from it
},

...

otherFunction: function() {

   this.showConfirmationDialog('Do you want to delete record?', function() {
      // Delete record
   });

}
于 2012-06-21T11:55:39.107 に答える