[Flex] 组件Tree系列 —— 阻止用户点击选中Tree中任何节点

mxml:

 1 <?xml version="1.0" encoding="utf-8"?>

 2 <!--功能描述:阻止用户点击选中Tree中任何节点-->

 3 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 

 4       xmlns:s="library://ns.adobe.com/flex/spark" 

 5       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"

 6       backgroundColor="0xffffff" creationComplete="application1_creationCompleteHandler(event)">

 7  <fx:Script>

 8   <![CDATA[

 9    import mx.events.FlexEvent;

10    import mx.events.ListEvent;

11    

12    protected function tree_itemClickHandler(event:ListEvent):void

13    {

14     var item:Object = event.currentTarget.selectedItem;

15     var nonSelectable:Boolean = ((item.hasOwnProperty("@clickEnabled")) && (item.(@clickEnabled == "false")));

16     if (nonSelectable) {

17      tree.selectedItem = null;

18     }

19    }

20    

21    protected function application1_creationCompleteHandler(event:FlexEvent):void

22    {

23     tree.openItems = data.actor[0];

24    }

25    

26   ]]>

27  </fx:Script>

28  <fx:Declarations>

29   <!-- 将非可视元素(例如服务、值对象)放在此处 -->

30   <fx:XML id="data" xmlns="">

31    <data>

32     <actor label="周星驰" clickEnabled="false">

33      <year label="1988">

34       <item label="《霹雳先锋》香港票房8916612 " clickEnabled="false"/>

35       <item label="《捕风汉子》香港票房3149395 " />

36       <item label="《最佳女婿》香港票房5807710 " />

37      </year>

38      <year label="1989">

39       <item label="《龙在天涯》香港票房6809853 " clickEnabled="false"/>

40       <item label="《义胆群英》香港票房7913329 " />

41       <item label="《流氓差婆》香港票房5624622 " />

42       <item label="《风雨同路》香港票房9335299 " />

43      </year>

44      <year label="1990 ">

45       <item label="《望夫成龙》香港票房13703364 " />

46       <item label="《咖喱辣椒》香港票房15777856 " />

47       <item label="《小偷阿星》香港票房7968106 " />

48       <item label="《师兄撞鬼》香港票房12128944 " clickEnabled="false"/>

49       <item label="《赌圣》香港票房41326156 " />

50       <item label="《无敌幸运星》香港票房18799869" />

51       <item label="《江湖最后一个大佬》香港票房5495811 " />

52      </year>

53     </actor>

54     <actor label="李连杰">

55      <year label="1992">

56       <item label="笑傲江湖之东方不败(1992)" clickEnabled="false" />

57       <item label="黄飞鸿之二男儿当自强(1992)" />

58       <item label="黄飞鸿之三狮王争霸(1992)" />

59      </year>

60      <year label="1993">

61       <item label="方世玉Ⅱ万夫莫敌(1993)" />

62       <item label="倚天屠龙记之魔教教主(1993)" />

63       <item label="黄飞鸿之铁鸡斗蜈蚣(1993)" />

64       <item label="太极张三丰(1993)" />

65      </year>

66      <year label="1994">

67       <item label="新少林五祖(1994)" />

68       <item label="精武英雄(1994)" />

69       <item label="中南海保镖(1994) " />

70       <item label="给爸爸的信(1995" />

71      </year>

72      <year label="1995">

73       <item label="鼠胆龙威(1995)" />

74       <item label="给爸爸的信(1995" />

75      </year>

76     </actor>

77    </data>

78   </fx:XML>

79  </fx:Declarations>

80  <mx:Tree id="tree" dataProvider="{data}" labelField="@label" showRoot="false" width="320" rowCount="8" itemClick="tree_itemClickHandler(event)"/>

81 </s:Application>

 

你可能感兴趣的:(Flex)