如何动态更改tree的节点的图标

2025-05-14 08:51:31
推荐回答(2个)
回答1:

修改tree节点的图标的步骤如下:
首先,在src下建立一个assets文件夹,放几张图片;
其次,编写代码如下:



[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=










]]>

height="450" id="treeXml"
dataProvider="{departmentTree}" labelField="@name"
showDataTips="true" iconFunction="SetIcon" />

最后,运行效果即可。

回答2:

Ext动态改变图标没有直接的方法调用的.
一般要先获得节点的UI,然后获得图标元素才能修改,相对复杂.

myNode.on('click',function(node){
node.getUI().getIconEl().src = 'img/1.gif';
});

不知道你问的是什么tree,希望能够帮到你