请教EXT布局时,加载多颗树时,只能显示一颗树,其它无法显示。
布局采用border,在导航栏分了三栏,每一栏均加载同样的一颗树做测试,结果发现,只有一个栏目中有显示,其它栏目中均无法显示,是什么原因,怎么解决?请教了。
如附件图所示:
树的代码,非常简单,其它的树,只在id和text方面设置成不一样进行加载。
InfoSystem.desktop.treeP = new Ext.tree.TreePanel({ animate : "true", loader : new Ext.tree.TreeLoader({}), xtype : "treepanel", id : "treep", bufferResize : false, root : new Ext.tree.AsyncTreeNode({ expandable : true, text : "主菜单1", iconCls : 'feed-parent-icon', draggable : false, id : "123", bufferResize : false, leaf : false,// 是否为叶子节点 children : [{ text : '测试12', iconCls : 'feed-parent-icon', children : [{ id : 'odf1', text : "ODF", iconCls : 'feed-icon', leaf : true }, { id : 'wgodf1', text : "武广ODF", iconCls : 'feed-icon', leaf : true }] }, { id : 'child21', iconCls : 'feed-parent-icon', text : '测试21', children : [{ id : 'ddf1', text : "DDF", iconCls : 'feed-icon', leaf : true }] }, { text : '测试31', iconCls : 'feed-parent-icon', children : [{ id : 'link1', text : "链路", iconCls : 'feed-icon', leaf : true }] }], listeners : { /* * "click":function(e) { Ext.Msg.alert(e.id); } */ } }) // containerScroll : "true" });
原因很简单.一个树对象渲染到一个地方后,你再渲染到其他地方时,他会在之前的地方消失,就这么简单
在开发过程中要避免.尽量代码重用.写成一个类,然后去new多次.这样就是多个对象
还有就是尽量不要使用id
一棵树实例只能显示在一个地方,你要显示多个地方,得实例化多棵树