0

嗨朋友这是我的要求:

当我双击“搜索”选项卡中的一个项目时,应该在“测试组树”选项卡中打开(展开)该特定项目。搜索选项卡中的项目是列表测试组树中的项目是 TreeItem。据我所知,在其他选项卡中展开树项目的唯一方法是使用其标签名称(唯一)。

在这里,我使用下面提到的代码来实现我的要求。现在,当我双击“搜索”选项卡中的项目时,“测试组树”选项卡正确打开,但 SelectedItem 未展开(按预期在另一个选项卡中打开 - 只有“测试组树”选项卡打开,没有其他反应)。请帮我实现我的要求。

private function TSTree_itemDoubleClick(event:ListEvent):void{
    var selectedItem: TSTreeItem = TSTreeItem(TSTreeTestGroup.getSelectedFolderItem());
    this.TSTreeTestGroup.tabMain.selectedIndex=0; // Here i am trying to open a next tab(it works)

    //var selectedSampleItem: TSTreeItem = PLTreeItem(TSTreeTestGroup.treTree.getChildByName(selectedItem.label));
    TestGroupTree(TestGroupManager(this).TSTreeTestGroup).loadPartialTreeItem(selectedItem);  // Here i actually want to refresh the particular tree item       
    TestGroupTree(TestGroupManager(this).TSTreeTestGroup).treTree.expandItem(selectedItem,true,false); // here i am trying to expand the particular tree item
    //TestGroupManager(TestGroupTree(TSTree(event.currentTarget).parentDocument).parentDocument).TSTreeTestGroup.treTree.expandItem(selectedItem, true, false);
    //TestGroupManager(TestGroupTree(TSTree(event.currentTarget).parentDocument).parentDocument).TSTreeTestGroup.loadPartialTreeItem(this.TSTreeTestGroup.treTree.getChildByName(selectedItem.label);
    // in the following i am tryin to get the TreeItemName and expand it accordingly
    TestGroupTree(TestGroupManager(this).TSTreeTestGroup).treTree.expandItem(this.TSTreeTestGroup.treTree.getChildByName(selectedItem.label), true, true);
}

<?xml version="1.0"?>
<mx:Box xmlns:mx="http://www.adobe.com/2006/mxml" implements="integras.TS.component.TSTreeComponent"
    show="Component_Show();" 
    remove="Component_Remove();" >
<mx:TabNavigator id="tabMain" change="tabMain_Change();" styleName="plTitleWindowTabNavigator"  creationPolicy="all" >
        <mx:Canvas label="Test Group Tree">
            <ns1:TSTree dataProvider="{dpTree}" updateComplete="treTree_UpdateComplete();" iconFunction="getTreeIcon" labelField="label" iconField="icon" showRoot="false"  allowMultipleSelection="true" id="treTree" doubleClickEnabled="true" itemDoubleClick="treTree_ItemDoubleClick(event);"  itemClick="treTree_ItemClick(event);" itemOpen="treTree_ItemOpen(event);" >
            </ns1:TSTree>
        </mx:Canvas>
        <mx:Canvas label="Search" width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off">
            <mx:Canvas>
                <mx:HRule/>
                <mx:List dataProvider="{dpSearch}"  dragEnabled="false" labelField="label" iconField="icon" id="lstSearch" doubleClickEnabled="true" itemDoubleClick="lstSearch_ItemDoubleClick(event);" itemClick="lstSearch_ItemClick(event);">
                </mx:List>
            </mx:Canvas>
    </mx:Canvas>
</mx:TabNavigator>
</mx:Box>

提前致谢。如果您有任何疑问,请告诉我。

4

1 回答 1

1

如果找到展开节点,请尝试在树中搜索所选项目。我认为问题可能是您传递给树以进行扩展的所选项目。

检查此示例是否对您有帮助

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" verticalAlign="middle">
    <mx:Script>
        <![CDATA[
            import mx.messaging.management.Attribute;
            import mx.events.ListEvent;

            import mx.controls.Alert;
            import mx.collections.XMLListCollection;

            [Bindable]
            private var searchResult:XMLList;
            private var searchResultIndex:uint = 0;

            private function findByLabel(event:Event):void
            {
                var searchStr:String = List(event.currentTarget).selectedItem.@label;
                tabMain.selectedIndex = 0;
                tree.openItems = [];
                //xmlDP.descendants().(@label == List(evt.currentTarget).selectedItem.@label)[0]
                searchResult = xmlDP.descendants().(@label.toLowerCase().search(searchStr.toLowerCase()) > -1);
                searchResultIndex = 0;
                if (searchResult[searchResultIndex] != undefined)
                    expandNode(searchResult[searchResultIndex]);
            }

            private function expandNode(xmlNode:XML):void
            {
                while (xmlNode.parent() != null) {
                    xmlNode = xmlNode.parent();
                    tree.expandItem(xmlNode, true, false);
                }
            }
      ]]>
    </mx:Script>

    <!-- Sample tree data -->
     <mx:XML id="xmlDP">
        <root>
                <node label="Parent 1">
                    <node label="Child 1"/>
                    <node label="Child 2">
                        <node label="Grandchild 1"/>
                        <node label="Grandchild 2"/>
                    </node>
                    <node label="Child 3"/>
                    <node label="Child 4"/>
                    <node label="Child 5">
                        <node label="Grandchild 1"/>
                        <node label="Grandchild 2"/>
                    </node>
                </node>
            </root>
    </mx:XML>

    <mx:XMLListCollection id="xmlMenuList" source="{xmlDP.*}"/>


    <mx:XMLList id="listData">
          <data>
            <node label="Parent 1" />
            <node label="Child 1"/>
            <node label="Child 2"/>
            <node label="Grandchild 1"/>
            <node label="Grandchild 2" />
            <node label="Child 3"/>
            <node label="Child 4"/>
            <node label="Child 5"/>
            <node label="Grandchild 1"/>
            <node label="Grandchild 2" />
        </data>
    </mx:XMLList>


    <mx:TabNavigator id="tabMain" creationPolicy="all" width="100%" >
            <mx:Canvas label="Test Group Tree">
                <mx:Tree dataProvider="{xmlMenuList}" labelField="@label" iconField="icon" showRoot="false"  
                         allowMultipleSelection="true" id="tree" doubleClickEnabled="true" width="100%">
                </mx:Tree>
            </mx:Canvas>
            <mx:Canvas label="Search" width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off">
                <mx:Canvas width="100%">
                    <mx:HRule/>
                    <mx:List dataProvider="{listData.node}"  dragEnabled="false" labelField="@label" id="lstSearch"
                             width="100%" itemClick="findByLabel(event)">
                    </mx:List>
                </mx:Canvas>
            </mx:Canvas>
    </mx:TabNavigator>


</mx:Application>
于 2012-04-30T13:53:04.133 回答