2012-10-17 86 views

回答

1

創建定製呈現這樣的:

package com.simmone.renderers { 
    import mx.collections.*; 
    import mx.controls.treeClasses.*; 
    import mx.controls.listClasses.ListBase; 

    public class MyTreeItemRenderer extends TreeItemRenderer { 
    public function MyTreeItemRenderer() { 
     super(); 
    } 

    override protected function updateDisplayList(unscaledWidth:Number, 
                unscaledHeight:Number):void { 
     super.updateDisplayList(unscaledWidth, unscaledHeight); 

     if(data.children.length == 0) { 
     super.disclosureIcon.visible = false; 
     } 
    } 
    } 
} 

MXML:

<fx:Script> 
    <![CDATA[ 
     import mx.collections.ArrayCollection; 

     private var dataArray:Array = [ 
     {label:"father1", children: 
      [{label:"child1"}, 
      {label:"child2"}]}, 
     {label:"father2", children:[]}]; 

     [Bindable] 
     private var dataList:ArrayCollection = new ArrayCollection(dataArray); 
    ]]> 
    </fx:Script> 

<mx:Tree id="tr1" width="100%" height="80" 
      dataProvider="{dataList}" 
      labelField="label" 
      borderVisible="false" 
      itemRenderer="com.simmone.renderers.MyTreeItemRenderer"/> 

,我發現,如果使用的XMLList,沒有這個問題,如果沒有孩子,將不顯示圖標discloure 。

+0

優秀的解決方案,謝謝。 –