2011-06-07 50 views
18

如何使用自定义按钮显示ExtJS消息框。带自定义按钮的ExtJs消息框

我想要一个带有自定义消息和“取消”和“取消激活”按钮的消息框。 请给点意见。

buttons: [{ 
    text: "Cancel", 
    handler: function() { 
     Ext.MessageBox.hide(); 
     //submitTicketForm(); 
    } 
},{ 
    text: "Deactivate", 
    handler: function() { 
     Ext.MessageBox.hide(); 
    } 
}], 

我正在使用它,但没有得到任何按钮。

回答

8

MessageBox的是用于提示,显示,警示内部管理窗口的单一实例等

您可以通过在一个字符串传递作秀这样的改变buttonText:

buttons: {ok: "Foo", cancel: "Bar"} 

参见: MessageBox

buttons: { 
       ok: "Foo", 
       handler: function(){ 
        Ext.MessageBox.hide(); 

       }, 
       cancel: "Bar", 
       handler: function(){ 
        Ext.MessageBox.hide(); 
       } 
     } 
+0

感谢您的重播..它工作正常,但h当我试图添加一个按钮的处理程序,按钮没有越来越........谢谢 – MNR 2011-06-07 06:42:26

+1

添加此:'fn:function(btn){\t console.log('btn'+ btn );}' – MMT 2011-06-07 07:15:47

+1

我认为重要的是要注意''buttons'属性只有当你创建一个新的消息框时才可用。如果你使用'Ext.Msg.show({config})''没有'button'属性! – Patrick 2013-08-31 04:25:51

16

在ExtJS的4,你可以让你自己的组件是这样的:

Ext.define('App.view.MyDialog', { 
    /** 
    * Shows the dialog. 
    */ 
    show: function() { 
     var dialog = Ext.create('Ext.window.MessageBox', { 
      buttons: [{ 
       text: 'baz', 
       iconCls: 'icon-add', 
       handler: function() { 
        dialog.close(); 
       } 
      }] 
     }); 

     dialog.show({ 
      title: 'foo!', 
      msg: '<p>bar?</p>', 
      icon: Ext.MessageBox.WARNING 
     }); 

     dialog.setHeight(160); 
     dialog.setWidth(420); 
    } 
}); 

则:

var dialog = Ext.create('App.view.MyDialog'); 
dialog.show(); 
+2

您可以定义一个类并在其中创建一个组件。为什么不扩展Messagebox? – A1rPun 2013-01-24 04:31:22

2

使用 'buttonText' 而不是 '按钮',

buttonText: {ok: 'Deactivate', cancel: 'Cancel'}, 
fn: function(btn) { 
    if (btn === 'ok') { 
     Ext.MessageBox.hide(); 
    } else { 
     Ext.MessageBox.hide(); 
    } 
} 
0

在ExtJS的4和ExtJS的5,设置自定义文本按钮,您需要同时使用buttonsbuttonText配置:

buttons: [{ 
    Ext.Msg.OK 
}], 
buttonText: { 
    ok: "Custom text" 
}, 
fn: function() { 
    // ...handle OK button 
}