Preventing specific items from being selected in a Flex Tree control

简介:

The following example shows you how you can prevent any item from being selected by adding an attribute (named “clickable”, but you could name it anything you wanted) and using E4X expressions to determine if the currently clicked item should be selectable or not.

Full code after the jump.

 

Note that in the following example, items with the “(X)” suffix are not-selectable, only the following nodes should be selectable: “Grandchild 1″, “Grandchild 2″, and “Child 4″.

<? xml version="1.0" encoding="utf-8" ?>
<!--  http://blog.flexexamples.com/2008/01/16/preventing-specific-items-from-being-selected-in-a-flex-tree-control/  -->
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white"
        creationComplete
="init();" >

    
< mx:Script >
        
<![CDATA[
            import mx.events.ListEvent;

            private function init():void {
                tree.openItems = dp..node;
            }

            private function tree_itemClick(evt:ListEvent):void {
                var item:Object = evt.currentTarget.selectedItem;
                var nonSelectable:Boolean = ((item.hasOwnProperty("@clickable")) && (item.(@clickable == "false")));
                if (nonSelectable) {
                    tree.selectedItem = null;
                }
            }
        
]]>
    
</ mx:Script >

    
< mx:XML  id ="dp" >
        
< root >
            
< node  label ="Parent 1 (X)"  clickable ="false" >
                
< node  label ="Child 1 (X)"  clickable ="false"   />
                
< node  label ="Child 2 (X)"  clickable ="false" >
                    
< node  label ="Grandchild 1"   />
                    
< node  label ="Grandchild 2"   />
                
</ node >
                
< node  label ="Child 3 (X)"  clickable ="false"   />
                
< node  label ="Child 4"   />
            
</ node >
        
</ root >
    
</ mx:XML >

    
< mx:Tree  id ="tree"
            dataProvider
="{dp}"
            showRoot
="false"
            labelField
="@label"
            width
="200"
            itemClick
="tree_itemClick(event);"   />

</ mx:Application >

    本文转自 OldHawk  博客园博客,原文链接http://www.cnblogs.com/taobataoma/archive/2008/01/20/1045919.html :,如需转载请自行联系原作者




相关文章
|
23天前
|
容器
Bootstrap5 Flex(弹性)布局4
排序:.order 类可设置弹性子元素的排序,范围从 .order-1 至 .order-12,数字越小优先级越高。外边距:.ms-auto 和 .me-auto 分别用于设置子元素的右侧和左侧外边距为 auto。包裹:.flex-nowrap(默认)、.flex-wrap 和 .flex-wrap-reverse 用于控制弹性容器中的子元素是否换行及换行方向。