flex:Tree点击一行打开关闭节点
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" ?? ? ? ?layout="vertical" ?? ? ? ?verticalAlign="middle" ?? ? ? ?backgroundColor="white"> ? ?? ?<mx:Script> ?? ? ? ?<![CDATA[ ?? ? ? ? ? ?import mx.collections.ICollectionView; ?? ? ? ? ? ?import mx.events.ListEvent; ?? ? ? ? ? ?private function tree_itemClick(evt:ListEvent):void { ?? ? ? ? ? ? ? ?var item:Object = Tree(evt.currentTarget).selectedItem; ?? ? ? ? ? ? ? ?if (tree.dataDescriptor.isBranch(item)) { ?? ? ? ? ? ? ? ? ? ?tree.expandItem(item,!tree.isItemOpen(item),true); ?? ? ? ? ? ? ? ?} ?? ? ? ? ? ?} ?? ? ? ? ? ?private function tree_labelFunc(item:XML):String { ?? ? ? ? ? ? ? ?var children:ICollectionView; ?? ? ? ? ? ? ? ?var suffix:String = ""; ?? ? ? ? ? ? ? ? ? ?children = tree.dataDescriptor.getChildren(item); ?? ? ? ? ? ? ? ? ? ?suffix = " (" + children.length + ")"; ?? ? ? ? ? ? ? ?return item[tree.labelField] + suffix; ?? ? ? ?]]> ?? ?</mx:Script> ?? ?<mx:XML id="dp"> ?? ? ? ?<root> ?? ? ? ? ? ?<folder label="One"> ?? ? ? ? ? ? ? ?<folder label="One.A"> ?? ? ? ? ? ? ? ? ? ?<item label="One.A.1" /> ?? ? ? ? ? ? ? ? ? ?<item label="One.A.2" /> ?? ? ? ? ? ? ? ? ? ?<item label="One.A.3" /> ?? ? ? ? ? ? ? ? ? ?<item label="One.A.4" /> ?? ? ? ? ? ? ? ? ? ?<item label="One.A.5" /> ?? ? ? ? ? ? ? ?</folder> ?? ? ? ? ? ? ? ?<item label="One.1" /> ?? ? ? ? ? ? ? ?<item label="One.2" /> ?? ? ? ? ? ?</folder> ?? ? ? ? ? ?<folder label="Two"> ?? ? ? ? ? ? ? ?<item label="Two.1" /> ?? ? ? ? ? ? ? ?<folder label="Two.A"> ?? ? ? ? ? ? ? ? ? ?<item label="Two.A.1" /> ?? ? ? ? ? ? ? ? ? ?<item label="Two.A.2" /> ?? ? ? ?</root> ?? ?</mx:XML> ?? ?<mx:Tree id="tree" ?? ? ? ? ? ?dataProvider="{dp}" ?? ? ? ? ? ?showRoot="false" ?? ? ? ? ? ?labelField="@label" ?? ? ? ? ? ?labelFunction="tree_labelFunc" ?? ? ? ? ? ?width="300" ?? ? ? ? ? ?rowCount="6" ?? ? ? ? ? ?itemClick="tree_itemClick(event);" /> </mx:Application> 来自:http://yecon.blog.hexun.com/28900948_d.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |