首页 > 解决方案 > 如何使用 ExtJS 面板渲染器配置添加点击事件?

问题描述

现在,在配置渲染器中,我不能调用 tClick;有什么办法可以满足我的需求吗?

代码是:

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.create('Ext.panel.Panel', {
            title: 'Table Layout',
            width: 300,
            layout: 'form',
            items: [{
                xtype: 'displayfield',
                fieldLabel: 'Home',
                name: 'home_score',
                renderer: function (val) {
                    return "<button onclick='this.tClick;'>test</button>";
                }
            }],
            buttons: [{
                text: 'Upload',
                handler: this.tClick
            }],
            renderTo: Ext.getBody()
        });
    },

    tClick: function () {
        alert(1);
    },
});

在此处查看运行结果:https ://fiddle.sencha.com/#view/editor

标签: extjs

解决方案


您应该参考应用程序,例如Fiddle.getApplication().tClick().

Ext.application({
    name: 'Fiddle',

    launch: function () {
        let me =this;
        Ext.create('Ext.panel.Panel', {
            title: 'Table Layout',
            width: 300,
            layout: 'form',
            items: [{
                xtype: 'displayfield',
                fieldLabel: 'Home',
                name: 'home_score',
                renderer: function (val) {
                    return "<button onclick='Fiddle.getApplication().tClick();'>test</button>";
                }
            }],
            buttons: [{
                text: 'Upload',
                handler: this.tClick
            }],
            renderTo: Ext.getBody()
        });
    },

    tClick: function () {
        alert(1);
    },
});

推荐阅读