使用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
}
}
});
答案 0 :(得分:1)
您只需返回false
即可停止呈现组件。查看docs。
所以也许你的功能看起来像这样:
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;
}
}