在Flex中灵活运用openItems实现树刷新后打开原始节点


  法一:(直接使用openItems)      width="250" dataProvider="{firstObj}" labelField="label"/>    法二:(间接使用openItems)  思路大概如下: 1、首先拿到树中被打开的节点; 2、根据打开的节点进行判断,当打开节点为空时则打开根目录;如果打开节点不为空时,则将打开节点存入一个数组中,然后再调用openItems实现节点的打开。大致代码如下: var openOrg:Array = typeTree.openItems as Array; typeTree.invalidateList(); typeTree.validateNow(); // 保持打开状态 if(openOrg.length == 0) { typeTree.selectedIndex = 0; var root:XML = typeTree.selectedItem as XML; typeTree.expandItem(root, true); }else { var open:Array = new Array(); for each(var node:XML in openOrg) { if(node) { node = ParseXmlUtil.getFolderXMLById(node.@id, typeXML);//从树中获得节点 open.push(node); } } typeTree.openItems = open; 

你可能感兴趣的:(Flex)