代码:
--------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
[Embed(source="assets/max_over.gif")] //这是图片的相对地址
[Bindable]
public var OKicon:Class;
[Embed(source="assets/close_over.gif")] //这是图片的相对地址
[Bindable]
public var NOicon:Class;
//设置不同图标
private function iconFun(item:Object):*
{
var xml:XML = item as XML;
if(xml.attribute("bool") == true)
return OKicon;
else if(xml.attribute("bool") == false)
return NOicon;
}
]]>
</mx:Script>
<mx:XMLListCollection id="datatree" >
<mx:source>
<mx:XMLList>
<node label="NO1" bool="false">
<node label="NO11" bool="false">
<node label="NO111" bool="false"/>
</node>
<node label="NO22" bool="true"/>
</node>
<node label="NO2" bool="true">
<node label="NO11" bool="false">
<node label="NO111" bool="false"/>
</node>
<node label="NO22" bool="true">
<node label="NO222" bool="false"/>
</node>
</node>
</mx:XMLList>
</mx:source>
</mx:XMLListCollection>
<mx:Tree id="tree" y="40" width="100%" height="100%" fontFamily="Arial" fontSize="12"
dataProvider="{datatree}" labelField="@label" iconFunction="iconFun" />
</mx:Application>
2/
icon.source = iconClass;
不知道可不可以。以前在TileList和DataGrid中用过
{
super.commitProperties();
if(super.data){
if( super.data.@label=="调度时间"){
super.removeChild(DisplayObject(icon));
var iconClass:Class = iconDesign;
icon = new iconClass();
addChild(DisplayObject(icon));
}
}
}
本文介绍如何在Flex中使用MX组件库的Tree组件,并通过动态设置图标展示不同的节点状态。具体实现包括使用XMLListCollection作为数据源,定义自定义函数iconFun来根据节点属性选择合适的图标。
2623

被折叠的 条评论
为什么被折叠?



