Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在extjs 3.4面板项中添加函数处理程序_Javascript_Extjs - Fatal编程技术网

Javascript 如何在extjs 3.4面板项中添加函数处理程序

Javascript 如何在extjs 3.4面板项中添加函数处理程序,javascript,extjs,Javascript,Extjs,。当我运行并单击图标按钮时,它无法调用函数func_1();什么也没有出现。在屏幕上 Ext.onReady(function () { function func_1() { //some functionality } new_win = new Ext.Panel({ renderTo: Ext.getBody(), activeItem: 0, tbar: { items:

。当我运行并单击图标按钮时,它无法调用函数func_1();什么也没有出现。在屏幕上

Ext.onReady(function () {
    function func_1() {
        //some functionality
    }

    new_win = new Ext.Panel({
        renderTo: Ext.getBody(),
        activeItem: 0,
        tbar: {
            items: [{
                text: 'List',
                ref: '../prevButton',
                disabled: true,
                handler: function () {
                    new_win.getLayout().setActiveItem(0);
                    new_win.prevButton.disable();
                    new_win.nextButton.enable();
                }

            }, '-', {
                text: 'Icon',
                ref: '../nextButton',
                handler: function () {
                    new_win.getLayout().setActiveItem(1);
                    new_win.prevButton.enable();
                    new_win.nextButton.disable();
                }
            }]
        },
        items: [{
            html: 'hello'
        }, {
            handler: function () {
                func_1();
            }
        }]
    });
});

你能告诉我如何调用func_1()吗;或面板项中的处理程序?

无需从匿名函数中调用函数,您可以直接从处理程序中引用该函数

例如:

    tbar: {
                    items: {
                        xtype: 'toolbar',
                        style: 'border:0;',
                        items: [{
                            xtype: 'buttongroup',
                                items: [{
                                    id: 'btnAddItem',
                                    text: 'Add Item',
                                    icon: 'images/icons/add-icon.png',
                                    handler: add_item
                                }]
                            }]
                        }
                },
...
function add_item(){

}

您应该创建一个全局变量,然后可以在处理程序中看到如下范围:

Ext.onReady(function () {

var me = this;

function func_1() {
    //some functionality
}

new_win = new Ext.Panel({
    renderTo: Ext.getBody(),
    activeItem: 0,
    tbar: {
        items: [{
            text: 'List',
            ref: '../prevButton',
            disabled: true,
            handler: function () {
                new_win.getLayout().setActiveItem(0);
                new_win.prevButton.disable();
                new_win.nextButton.enable();
            }

        }, '-', {
            text: 'Icon',
            ref: '../nextButton',
            handler: function () {
                me.func_1();
                new_win.getLayout().setActiveItem(1);
                new_win.prevButton.enable();
                new_win.nextButton.disable();
            }
        }]
    },
    items: [{
        html: 'hello'
    }, {
        handler: function () {
            func_1();
        }
    }]
});