ExtJS 4或4.1的MessageBox自定义按钮

6
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个回答

19

刚刚发现了如何做到这一点,希望能对某些人有所帮助。正如你所看到的,你可以随心所欲地处理这些按钮。请注意,框架默认只有4个按钮,并且这是一个不容易克服的限制。在源代码中,有多个循环硬编码从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
    }
});

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
});​

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'
    }
});

希望这能对您有所帮助。

0
尝试这个解决方案:
<script type="text/javascript">
            (function () {
                Ext.override(Ext.MessageBox, {
                    buttonText: { yes: "Sí", no: "No", cancel: "Cancelar" }
                });
            })();
    </script>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接