问题描述
var panel = new Ext.Panel({title:'toolbar-changebar', renderTo:Ext.getBody(),tbar:[{text:'btn1',handler:function (){alert("btn1");}},{text:'btn2',handler:function (){ changeBar ();}}]});function changeBar (){var t=[{text:'abc'},{text:'aab'}];var tbItem = panel.tbar;panel.remove(panel.getTopToolbar().get(1));panel.getTopToolbar().add(t);panel.doLayout();}想要实现按btn2按钮时,将btn1,btn2去掉,更新为新的tbar ,t
解决方案
var panel = new Ext.Panel({title:'toolbar-changebar', renderTo:Ext.getBody(),tbar:[{text:'btn1',handler:function (){alert("btn1");}},{text:'btn2',handler:function (){ changeBar ();}}]});function changeBar (){var t=[{text:'abc'},{text:'aab'}];var tbItem = panel.getTopToolbar();tbItem.removeAll(); tbItem.add(t);panel.doLayout();}
解决方案二:
var panel = new Ext.Panel({ title:'toolbar-changebar', renderTo:Ext.getBody(), tbar:[{ text:'btn1', id:"btn1", handler:function (){ alert("btn1"); } },{ text:'btn2', handler:function (){ changeBar (); } }] }); function changeBar (){ var t=[{text:'abc'},{text:'aab'}]; var tbItem = panel.getTopToolbar(); tbItem.remove("btn1",true);//第1个参数删除组件的id, //第2个参数 设置为true将自动调用被删组件的Ext.Component.destroy 函数 tbItem.add(t); tbItem.doLayout(); }
解决方案三:
上面错了点应该是 tbItem.doLayout();