• 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>

  • 相关阅读:
    如何手工设置归档目录
    C#字符串格式化说明(String.Format) (zz.IS2120)
    win7 GodMode
    金山软件公司创始人求伯君简介 (is2120.zz)
    【百度地图】安卓系统的百度地图可以下载离线地图,这个很省流量和时间
    手机用笔记本wifi上网【无USB、无软件、无无线路由器】
    安卓版有道词典的离线词库《21世纪大英汉词典》等
    秀秀我的巨无霸手机P1000
    [转载]环游澳大利亚18天——前传与攻略
    [转载]环游澳大利亚18天——前传与攻略
  • 原文地址:https://www.cnblogs.com/taobataoma/p/1045919.html
Copyright © 2020-2023  润新知