2017-01-24 60 views
0

我正在維護一個較大的傳統Flex 4.6項目,該項目拒絕死亡,並且遇到了Mx Tree組件,我無法解決該問題。要點是,將項目添加到現有節點展品奇怪的行爲,如果項目是重複的。如果節點是使用唯一項目創建的,則該組件的行爲與預期相同。將重複項添加到現有節點時Mx樹失敗

例如,下圖顯示了將文件「AAAAA.png」多次添加到現有節點的結果。突出顯示是瘋狂的,組件似乎對它有多少項目感到困惑(已經測試過)。

我試過重新設置數據提供程序等的「刷新樹」破解(下圖),我在各種支持Array Collections上調用刷新。我開始走下去,用一個Spark Tree代替Mx Tree,這是一個人想出來的,但它變成了太多的時間。

在我告訴客戶放棄這個功能之前,有沒有人想過這個問題可能是什麼?我比Flex開發人員更喜歡Actionscript,除了使用它們之外,我不瞭解組件的方式。

enter image description here


protected function vfAddToBtn_clickHandler(event:MouseEvent):void 
    { 
     if (virtualFoldersList.selectedItem == null){ 
      Alert.show("Please select a virtual folder to add to", "Add to Virtual Folder", Alert.OK); 

     } else { 
      if (briefcaseData.currentSelectionsList.length > 0){ 
       var vf:VirtualFolder = virtualFoldersList.selectedItem as VirtualFolder; 

       if (vf != null){ 
        vf.children.addAll(briefcaseData.currentSelectionsList); 
        vf.children.refresh(); 
        briefcaseData.virtualFoldersArray.refresh(); 
        refreshTree(virtualFoldersList); 

       } else { 
        trace("ERROR: vfAddToBtn_clickHandler vf is null"); 
       } 
      } 
     } 
    } 

 private function refreshTree(tree:Tree) : void 
     { 
      var selectedIndex : int = tree.selectedIndex; 
      var openItems : Object = tree.openItems; 
      tree.dataProvider = tree.dataProvider; 
      tree.openItems = openItems; 
      tree.validateNow(); 
      tree.selectedIndex = selectedIndex; 
     } 

回答

0

答案是...,從Flex的4.6 MX的Flex的樹是剛剛打破。我嘗試了一切,甚至從我試圖合併的兩個ArrayCollections的源數組中創建一個新的ArrayCollection(下面的代碼)。結果是一樣的:如果存在重複項目,則組件中突出顯示的翻轉項目是錯誤的,組件會對其包含的項目感到困惑。

唉。


protected function vfAddToBtn_clickHandler(event:MouseEvent):void 
      { 
       if (virtualFoldersList.selectedItem == null){ 
        Alert.show("Please select a virtual folder to add to", "Add to Virtual Folder", Alert.OK); 

       } else { 
        if (briefcaseData.currentSelectionsList.length > 0){ 
         var vf:VirtualFolder = virtualFoldersList.selectedItem as VirtualFolder; 

         if (vf != null){ 

          var temp: Array = new Array(); 
          var sourceArray: Array; 
          var i:int; 

          if (vf.children.length > 0){ 
           sourceArray = vf.children.source; 
           for (i=0; i < sourceArray.length; i++){ 
            temp.push(sourceArray[i]); 
           } 
          } 

          sourceArray = briefcaseData.currentSelectionsList.source; 
          for (i=0; i < sourceArray.length; i++){ 
           temp.push(sourceArray[i]); 
          } 

          vf.children = new ArrayCollection(temp); 
          vf.children.refresh(); 
          briefcaseData.virtualFoldersArray.refresh(); 
          refreshTree(virtualFoldersList); 

         } else { 
          trace("ERROR: vfAddToBtn_clickHandler vf is null"); 
         } 
        } 
       } 
      } 
0

是briefcaseData.currentSelectionsList的XMLList或XML?

相應地使用新的XML/XMLList中在下面一行

vf.children.addAll(briefcaseData.currentSelectionsList) 

vf.children.addAll(new XMLList(briefcaseData.currentSelectionsList)) 
+0

這是一個'ArrayCollection' –

+0

然後使用該行vf.children.addAll(新的ArrayCollection(briefcaseData.currentSelectionsList)) – Sumit

+0

謝謝 - 我只是想,一個更(創建一個新的'的ArrayCollection '我想合併的'ArrayCollections'的來源),而'Mx Tree'仍然對重複項目感到困惑。 –

0

我已經創建了我前面給出的答案一個示例應用程序,它是對我工作的罰款。請檢查這個代碼。

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" 
      creationComplete="creationCompleteHandler(event)"> 
<s:layout> 
    <s:VerticalLayout /> 
</s:layout> 
<fx:Declarations> 
    <fx:XML id="xmlData"><list> 
     <department title="Finance" code="200"> 
      <employee name="John H"/> 
      <employee name="Sam K"/> 
     </department> 
     <department title="Operations" code="400"> 
      <employee name="Bill C"/> 
      <employee name="Jill W"/> 
     </department> 
     <department title="Engineering" code="300"> 
      <employee name="Erin M"/> 
      <employee name="Ann B"/> 
     </department> 
    </list></fx:XML> 
    <fx:XML id="empData"><employee></employee></fx:XML> 
</fx:Declarations> 
<fx:Script> 

    import mx.collections.XMLListCollection; 
    import mx.events.FlexEvent; 

    [Bindable] 
    private var company:XML; 
    [Bindable] 
    private var companyData:XMLListCollection; 

    private function treeLabel(item:Object):String { 
     var node:XML = XML(item); 
     if (node.localName() == "department") 
      return [email protected]; 
     else 
      return [email protected]; 
    } 

    private function addEmployee():void { 
     if (tree.selectedItem.localName() == "employee") 
      return; 
     var newNode:XML = new XML(empData); 
     [email protected] = empName.text; 
     var dept:XMLList = XMLList(tree.selectedItem); 
     if (dept.length() > 0) { 
      dept.appendChild(newNode); 
      empName.text = ""; 
     } 
     companyData.refresh(); 
    } 

    private function removeEmployee():void { 
     var node:XML = XML(tree.selectedItem); 
     if (node == null) 
      return; 
     if (node.localName() != "employee") 
      return; 
     var children:XMLList = XMLList(node.parent()).children(); 
     for (var i:Number = children.length() - 1; i >= 0; i--) { 
      if (children[i][email protected] == [email protected]) { 
       delete children[i]; 
      } 
     } 
    } 

    private function creationCompleteHandler(event:FlexEvent):void { 
     company = new XML(xmlData); 
     companyData = new XMLListCollection(company.department) 
    } 
</fx:Script> 
<mx:Tree id="tree" top="72" left="50" dataProvider="{companyData}" 
     labelFunction="treeLabel" height="225" width="300" 
     defaultLeafIcon="{null}" folderClosedIcon="{null}" 
     folderOpenIcon="{null}"/> 
<mx:VBox> 
    <mx:HBox> 
     <mx:Button label="Add Operations Employee" click="addEmployee();" /> 
     <mx:TextInput id="empName" /> 
    </mx:HBox> 
    <mx:Button label="Remove Selected Employee" click="removeEmployee();" /> 
</mx:VBox>