0

使用 ExtJS,如何防止组件根据条件渲染到 DOM 中?代码可能是这样的(我使用 Sencha Architect 来生成代码,所以我不是 100% 熟悉语法)

Ext.define('MyApp.view.MyButton', {
    extend: 'Ext.button.Button',

    text: 'MyButton',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            listeners: {
                beforerender: {
                    fn: me.onButtonBeforeRender,
                    scope: me
                }
            }
        });

        me.callParent(arguments);
    },

    onButtonBeforeRender: function(component, eOpts) {
        if (MyCondition) {
            // all good, go on with rendering this component
        }
        else {
            // no good, abort, this component should not be rendered
        }
    }

});
4

1 回答 1

1

您可以返回false以停止组件的渲染。检查文档

所以也许你的函数看起来像这样:

onButtonBeforeRender: function(component, eOpts) {
    if (MyCondition) {
        // all good, go on with rendering this component
        return true;
    }
    else {
        // no good, abort, this component should not be rendered
        return false;
    }
}
于 2013-05-30T20:51:04.923 回答