ExtJS 4或4.1 MessageBox自定义按钮

时间:2012-09-04 12:14:46

标签: extjs4 extjs4.1

Ext.MessageBox.show({
    title:'Messagebox Title',
    msg: 'Are you sure want to delete?',
    buttons: {yes: "Some Button 1",no: "Some Button 2",cancel: "Some Button 3"}
});

ExtJS 4或4.1不支持此代码。按钮不显示。

4 个答案:

答案 0 :(得分:20)

刚刚知道如何做到这一点,希望它可以帮助某人。如您所见,您可以随意处理按钮。请注意,框架默认只有4个按钮,这是一个不容易克服的限制。在源中,存在从0到<0的硬编码的多个循环。 4。

Ext.MessageBox.show({
    title:'Messagebox Title',
    msg: 'Are you sure want to delete?',
    buttonText: {yes: "Some Button 1",no: "Some Button 2",cancel: "Some Button 3"},
    fn: function(btn){
        console.debug('you clicked: ',btn); //you clicked:  yes
    }
});

答案 1 :(得分:4)

您无法在方法show中执行此操作,因为方法中的按钮配置将一个数字作为参数,用于标识要显示的按钮。 您可以做的是预定义您的消息框,然后只显示它。

 var win = Ext.create('Ext.window.MessageBox', {
     width:300,
     height: 100,
     buttons: [
      {text: 'My button 1'},{
        text: 'My button 2'}
    ]
});

win.show({
     title:'Messagebox Title',
     msg: 'Are you sure want to delete?',
    icon: Ext.Msg.QUESTION
});​

答案 2 :(得分:3)

使用以下代码:

Ext.MessageBox.show({
    title:'Messagebox Title',
    msg: 'Are you sure want to delete?',
    buttonText: {                        
        yes: 'Some Button 1',
        no: 'Some Button 2',
        cancel: 'Some Button 3'
    }
});

希望它会对你有所帮助。

答案 3 :(得分:0)

试试这个解决方案:

<script type="text/javascript">
            (function () {
                Ext.override(Ext.MessageBox, {
                    buttonText: { yes: "Sí", no: "No", cancel: "Cancelar" }
                });
            })();
    </script>