利用iconFunction更改Tree图标

本文介绍如何使用FlexTree组件通过iconFunction属性自定义不同类型的节点图标,例如文件夹和工作区图标,并展示了具体的MXML代码实现。

(注:利用iconField只能更改叶子节点的图标。所以这里采用iconFunction)

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <!--[CDATA[ [Embed(source="folder.png")] //这是图片的相对地址 [Bindable] public var folder:Class; [Embed(source="workspace.png")] //这是图片的相对地址 [Bindable] public var workspace:Class; private function iconFun(item:Object):* { var xml:XML= XML(item); if(xml.attribute("type") == "folder") return folder; else if(xml.attribute("type") == "workspace") return workspace; } ]]--> </mx:Script> <mx:XML id="treedata"> <node label="ROOT"> <node label="Inbox" type="folder"> <node label="Marketing" type="workspace"/> <node label="Product Management" type="workspace"/> <node label="Personal" type="workspace"/> </node> <node label="Outbox" type="folder"> <node label="Professional" type="workspace"/> <node label="Personal" type="workspace"/> </node> <node label="Spam" type="workspace"/> <node label="Sent" type="folder"/> </node> </mx:XML> <mx:Tree width="398" height="300" x="98" y="52" showRoot="false" iconFunction="iconFun" dataProvider="{treedata}" iconField="@type" labelField="@label" /> </mx:Application>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值