2012-04-30 458 views
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> 

感谢Advance.Please让我知道如果您有任何疑问。

回答

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)[email protected]; 
       tabMain.selectedIndex = 0; 
       tree.openItems = []; 
       //xmlDP.descendants().(@label == List(evt.currentTarget)[email protected])[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>