18

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

我想要一个带有自定义消息和“取消”和“停用”按钮的消息框。请给出一些想法。

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

我像这样使用它,但没有得到任何按钮。

4

4 回答 4

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();
于 2011-11-27T12:37:35.507 回答
8

MessageBox 是内部管理的 Window 的单个实例,用于提示、显示、警报等。

您可以通过传入一个字符串来更改 buttonText,如下所示:

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

参考: 消息框

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

                },
                cancel: "Bar",
                handler: function(){
                    Ext.MessageBox.hide();
                }
        }
于 2011-06-07T06:09:17.920 回答
2

使用“buttonText”而不是“button”,

buttonText: {ok: 'Deactivate', cancel: 'Cancel'},
fn: function(btn) {
    if (btn === 'ok') {
        Ext.MessageBox.hide();
    }  else {
        Ext.MessageBox.hide(); 
    } 
}
于 2014-08-07T06:00:56.283 回答
0

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

buttons: [{
    Ext.Msg.OK
}],
buttonText: { 
    ok: "Custom text"
},
fn: function() { 
    // ...handle OK button
}
于 2014-12-15T07:51:49.813 回答