2009-11-18 49 views
1

我使用Flex樹的iconField屬性來動態設置節點應該使用的圖標。這對葉節點工作正常,但對於分支節點,它似乎並不尊重我的iconField,而只是顯示默認文件夾節點。爲什麼使用Flex Tree組件爲分支節點忽略iconField?

這裏有一個簡單的攝製:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> 

<mx:Script> 
    <![CDATA[ 
     [Embed("assets/icon1.png")] 
     public var icon1:Class; 

     [Embed("assets/icon2.png")] 
     public var icon2:Class; 
    ]]> 
</mx:Script> 

<mx:XML id="dp"> 
    <node label="Sales" icon="icon1"> 
     <node label="East" icon="icon2"/> 
     <node label="West" icon="icon2"/> 
    </node> 
</mx:XML> 

<mx:Tree dataProvider="{dp}" labelField="@label" iconField="@icon" 
    width="100%" height="100%" /> 

</mx:Application> 

什麼情況是,ICON2顯示了東方和西方的節點,但ICON1不顯示的銷售節點。我怎樣才能使這個工作?

回答

0

差不多! 您需要設置像這樣的folderOpenIcon和folderClosedIcon:

<mx:Tree dataProvider="{dp}" labelField="@label" iconField="@icon" 
     folderOpenIcon="{icon3}" 
     folderClosedIcon="{icon4}" 
     width="100%" height="100%" /> 
+0

啊,但我想要做的是有樹的不同節點不同的文件夾圖標。在我的情況下,他們根本就不是文件夾。相反,它們表示具有父子關係的不同對象。 – Marplesoft

1

我看到。 susichan是正確與iconFunction僅:

<mx:Script> 
    <![CDATA[ 
     [Embed("icon1.png")] 
     public var icon1:Class; 

     [Embed("icon2.png")] 
     public var icon2:Class; 

     [Embed("icon3.png")] 
     public var icon3:Class; 

     private function setIcons(item:Object):Class { 
      var iconClass:Class; 
      var classType:String = XML(item).attribute("icon"); 
      if(classType!="") 
       return this[classType]; 
      else 
       return null; 
     } 


    ]]> 
</mx:Script> 

<mx:XML id="dp"> 
    <root> 
      <node label="Sales" icon="icon1"> 
       <node label="East" icon="icon3"/> 
       <node label="West" icon="icon3"/> 
      </node> 
      <node label="Non-Sales" icon="icon2"> 
       <node label="East" icon="icon3"/> 
       <node label="West" icon="icon3"/> 
      </node> 
    </root> 
</mx:XML> 

<mx:Tree dataProvider="{dp.node}" labelField="@label" iconField="@icon" 
     iconFunction="setIcons" showRoot="true" 
     width="100%" height="100%" />