2011-11-05 62 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的美女之一就是能够利用绑定值。