main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:Script>
- <![CDATA[
- import mx.events.ListEvent;
- private function tree_itemClick(evt:ListEvent):void {
- var itemIsBranch:Boolean = tree.dataDescriptor.isBranch(tree.selectedItem);
- lbl.text = itemIsBranch.toString();
- }
- private function tree_labelFunc(item:XML):String {
- var returnStr:String = item.@label;
- var itemIsBranch:Boolean = tree.dataDescriptor.isBranch(item);
- if (itemIsBranch) {
- returnStr += " (BRANCH)";
- }
- return returnStr;
- }
- ]]>
- </mx:Script>
- <mx:XMLid="xmlDP">
- <node>
- <nodelabel="1.a" />
- <nodelabel="1.b" />
- <nodelabel="1.c">
- <nodelabel="1.c.i" />
- <nodelabel="1.c.ii" />
- <nodelabel="1.c.iii" />
- <nodelabel="1.c.iv" />
- <nodelabel="1.c.v" />
- </node>
- <nodelabel="1.d" />
- <nodelabel="1.e">
- <nodelabel="1.e.i" />
- <nodelabel="1.e.ii" />
- <nodelabel="1.e.iii">
- <nodelabel="1.e.iii.A" />
- </node>
- <nodelabel="1.e.iv" />
- </node>
- <nodelabel="1.f" />
- </node>
- </mx:XML>
- <mx:ApplicationControlBardock="true">
- <mx:FormstyleName="plain">
- <mx:FormItemlabel="isBranch():">
- <mx:Labelid="lbl" fontWeight="bold" />
- </mx:FormItem>
- </mx:Form>
- </mx:ApplicationControlBar>
- <mx:Treeid="tree"
- dataProvider="{xmlDP}"
- labelFunction="tree_labelFunc"
- showRoot="false"
- width="50%"
- rowCount="6"
- itemClick="tree_itemClick(event);"/>
- </mx:Application>
本文展示了一个使用Adobe Flex框架创建的Tree组件实例。该实例通过自定义的数据提供者和标签函数实现了动态显示分支节点的功能,并在点击节点时更新显示当前选中节点是否为分支。
130

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



