2011-11-05 66 views
1

我有一個應該在我的樹形控件中選擇的項目數組,正如你在我的代碼中看到的那樣,我將這個數組綁定到樹的selectedIndices屬性 所選項目在樹中沒有正確選擇(選擇一些其他項目,並且始終選擇root).Flex似乎「忽略」我的項目(選擇一些其他索引)我是否缺少某些東西?Flex樹沒有選擇(「突出顯示」)選定的結構

也許我是要對這個在錯誤的方式

感謝您的幫助

我的XMLList: - ?!

<fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
     <fx:XMLList id="XMLList"> 
     <node> 
      <node name="max"> 
       <node name="Emanuele" 
         surname="Tatti" age="23" wage="1200"/> 
       <node name="Francesco" 
         surname="Rapana " age="22" wage="1000"/> 
       <node name="Constantin" 
         surname="Moldovanu" age="23" wage="1200"/> 
       <node name="Marco" 
         surname="Casario" age="29" wage="1500"> 
        <node name="Marco" 
          surname="Casario" age="29" wage="1500"> 
         <node name="Marco" 
           surname="Casario" age="29" wage="1500"> 
          <node name="Marco" 
            surname="Casario" age="29" wage="1500"> 
          </node> 
         </node> 
        </node>     
       </node> 
      </node> 

     </node> 
     </fx:XMLList> 
</fx:Declarations> 

我的動作腳本功能: -

public function select_tree():Void 
{ 
tree.validateNow(); 
var allItems:Array = new Array(); 
for(var n:Int =2;n<7;n+2)  
{ 
     allItems[n]=n; // o/p- 2,4,6 
} 

tree.selectedIndices = allItems1; //2,4,6 items should select ,but 0,2,4,5 are selected why? 
     } 

*****My MXML:-***** 
<mx:Button id="btn" label="Find Unmatch Nodes" width="221" height="30" click="select_tree()"/> 



<mx:Tree id="tree" right="10" top="54" bottom="10" width="49.5%" dataProvider="{XMLList}" 
    fontFamily="Verdana" fontSize="11" showScrollTips="true" 
    allowMultipleSelection="true" 
    alternatingItemColors="[#F5F5F5]" 
    labelField="@label" selectionColor="#ECF335" showRoot="false"/> 

回答

2

您可以通過tree.selectedIndices設置allItems1(而不是allItems)在你的代碼錯誤。

tree.selectedIndices = allItems1; 

爲什麼你不創建一個Bindable數組,並將它設置爲樹的selectedIndices屬性?

[Bindable] 
public var selectedTreeValues:Array = new Array(); 

... 

<mx:Tree id="tree" right="10" top="54" bottom="10" width="49.5%" 
    dataProvider="{XMLList}" 
    fontFamily="Verdana" fontSize="11" showScrollTips="true" 
    allowMultipleSelection="true" 
    alternatingItemColors="[#F5F5F5]" 
    labelField="@label" selectionColor="#ECF335" showRoot="false" 
    selectedIndices="selectedTreeValues" 
/> 

最後,痕量表示出來,而不必手動地做呢? Flex的美女之一就是能夠利用綁定值。