如何动态更改tree的节点的图标
1个回答
展开全部
修改tree节点的图标的步骤如下:
首先,在src下建立一个assets文件夹,放几张图片;
其次,编写代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="14" layout="absolute">
<mx:Script>
<![CDATA[
[Embed(source="assets/boy.jpg")]
public var boyIcon:Class;
[Embed(source="assets/girl.jpg")]
public var girlIcon:Class;
// 根据结点的属性设置节点图标
private function SetIcon(item:Object):*
{
var xml:XML = item as XML;
if(xml.attribute("sex")=="boy")
{
return boyIcon;
}
else
{
return girlIcon; }
}
// Tree控件的数据源
[Bindable]
public var departmentTree:XML=
<member name="小李" sex="boy">
<member name="王志" sex="boy">
<member name="赵强" sex="boy" />
<member name="李丽" sex="girl" />
</member>
<member name="韩梅梅" sex="girl">
<member name="孙艳" sex="girl"/>
</member>
</member>
]]>
</mx:Script>
<mx:Tree x="216" y="0" width="318"
height="450" id="treeXml"
dataProvider="{departmentTree}" labelField="@name"
showDataTips="true" iconFunction="SetIcon" />
</mx:Application>
最后,运行效果即可。
首先,在src下建立一个assets文件夹,放几张图片;
其次,编写代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="14" layout="absolute">
<mx:Script>
<![CDATA[
[Embed(source="assets/boy.jpg")]
public var boyIcon:Class;
[Embed(source="assets/girl.jpg")]
public var girlIcon:Class;
// 根据结点的属性设置节点图标
private function SetIcon(item:Object):*
{
var xml:XML = item as XML;
if(xml.attribute("sex")=="boy")
{
return boyIcon;
}
else
{
return girlIcon; }
}
// Tree控件的数据源
[Bindable]
public var departmentTree:XML=
<member name="小李" sex="boy">
<member name="王志" sex="boy">
<member name="赵强" sex="boy" />
<member name="李丽" sex="girl" />
</member>
<member name="韩梅梅" sex="girl">
<member name="孙艳" sex="girl"/>
</member>
</member>
]]>
</mx:Script>
<mx:Tree x="216" y="0" width="318"
height="450" id="treeXml"
dataProvider="{departmentTree}" labelField="@name"
showDataTips="true" iconFunction="SetIcon" />
</mx:Application>
最后,运行效果即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询