2013-05-30 45 views
0

使用ExtJS,如何防止組件根據條件呈現到DOM中?該代碼可能會是這樣的(我使用煎茶建築師生成代碼,所以我不是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 
     } 
    } 

}); 

回答

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