zoukankan      html  css  js  c++  java
  • Using the isBranch() method to determine if a Tree item is a branch or leaf

    The following example shows how you can use the isBranch() method to determine if a specific node in a Tree control is a branch (folder) or leaf (item).
    <?xml version="1.0" encoding="utf-8"?>
    <!-- http://blog.flexexamples.com/2007/11/30/using-the-isbranch-method-to-determine-if-a-tree-item-is-a-branch-or-leaf/ -->
    <mx:Application xmlns: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:XML id="xmlDP">
            
    <node>
                
    <node label="1.a" />
                
    <node label="1.b" />
                
    <node label="1.c">
                    
    <node label="1.c.i" />
                    
    <node label="1.c.ii" />
                    
    <node label="1.c.iii" />
                    
    <node label="1.c.iv" />
                    
    <node label="1.c.v" />
                
    </node>
                
    <node label="1.d" />
                
    <node label="1.e">
                    
    <node label="1.e.i" />
                    
    <node label="1.e.ii" />
                    
    <node label="1.e.iii">
                        
    <node label="1.e.iii.A" />
                    
    </node>
                    
    <node label="1.e.iv" />
                
    </node>
                
    <node label="1.f" />
            
    </node>
        
    </mx:XML>

        
    <mx:ApplicationControlBar dock="true">
            
    <mx:Form styleName="plain">
                
    <mx:FormItem label="isBranch():">
                    
    <mx:Label id="lbl" fontWeight="bold" />
                
    </mx:FormItem>
            
    </mx:Form>
        
    </mx:ApplicationControlBar>

        
    <mx:Tree id="tree"
                dataProvider
    ="{xmlDP}"
                labelFunction
    ="tree_labelFunc"
                showRoot
    ="false"
                width
    ="50%"
                rowCount
    ="6"
                itemClick
    ="tree_itemClick(event);" />

    </mx:Application>
  • 相关阅读:
    Python全栈开发记录_第七篇(模块_time_datetime_random_os_sys_hashlib_logging_configparser_re)
    Python全栈开发记录_第六篇(生成器和迭代器)
    Python全栈开发记录_第五篇(装饰器)
    Python全栈开发记录_第四篇(集合、函数等知识点)
    Python全栈开发记录_第三篇(linux(ubuntu)的操作)
    Python全栈开发记录_第二篇(文件操作及三级菜单栏增删改查)
    Python全栈开发记录_第一篇(循环练习及杂碎的知识点)
    NET控件Designer架构设计
    如何把Excel中的单元格等对象保存成图片
    “某某云词典” – 纠结的初体验
  • 原文地址:https://www.cnblogs.com/taobataoma/p/1039370.html
Copyright © 2011-2022 走看看