一个openlaszlo添加删除树节点的例子

阅读更多

应一位网友的要求,做了这个例子,实现添加删除目录,但是没有象他那样去移动按钮的位置。

xml 代码
  1. <canvas debug="true" fontsize="12">  
  2.     <include href="lz/tree.lzx"/>  
  3.     <dataset name="treedata">  
  4.         <root>  
  5.             <project name="演示方案" isleaf="false">  
  6.                 <scheme name="业务模型一" isleaf="false">  
  7.                     <item name="业务协作流程图" isleaf="true"/>                   
  8.                     <item name="组织机构图" isleaf="true"/>                     
  9.                 scheme>  
  10.                 <scheme name="业务模型二" isleaf="false">  
  11.                     <item name="业务协作流程图" isleaf="true"/>                   
  12.                     <item name="组织机构图" isleaf="true"/>                         
  13.                 scheme>  
  14.             project>     
  15.             <project name="视频" isleaf="false">  
  16.                 <scheme name="视频分类一" isleaf="false">  
  17.                     <item name="视频一" isleaf="true"/>                   
  18.                 scheme>  
  19.                 <scheme name="视频分类二" isleaf="false">  
  20.                     <item name="视频一" isleaf="true"/>                   
  21.                 scheme>  
  22.             project>  
  23.             <project name="图片" isleaf="false">  
  24.                 <scheme name="图片分类一" isleaf="false">  
  25.                     <item name="图片一" isleaf="true"/>                   
  26.                 scheme>  
  27.                 <scheme name="图片分类二" isleaf="false">  
  28.                     <item name="图片一" isleaf="true"/>                   
  29.                 scheme>  
  30.             project>  
  31.         root>        
  32.     dataset>  
  33.     <handler name="oninit">  
  34.         canvas.treecontainer.projecttree.datapath.setPointer(treedata.childNodes[0]);   
  35.     handler>  
  36.       
  37.     <attribute name="selecteditem" value="null"/>  
  38.     <button name="adddir" x="0" y="4" text="Add Dir" height="24">  
  39.         <handler name="onclick">  
  40.             if(canvas.selecteditem==null){   
  41.                var projectnode = new LzDataElement('project');   
  42.                projectnode.setAttr('name','NEW DIR');   
  43.                projectnode.setAttr('isleaf',false);   
  44.                canvas.treecontainer.projecttree.datapath.p.appendChild(projectnode);   
  45.             }   
  46.         handler>  
  47.     button>  
  48.     <button name="deldir" x="80" y="4" text="Del Dir" height="24">  
  49.         <handler name="onclick">  
  50.             if(canvas.selecteditem!=null){   
  51.                 canvas.selecteditem.deleteNode();   
  52.                 canvas.selecteditem = null;   
  53.             }   
  54.         handler>  
  55.     button>  
  56.     <view name="treecontainer" x="10" y="30" width="200" height="400" bgcolor="#F5F5F5" clip="true">  
  57.         <tree name="projecttree" text="分类目录" datapath="" isleaf="false" open="true">  
  58.             <tree datapath="*"  text="$path{'@name'}" xindent="20" y="18" closesiblings="false" expander="lztree_plusminus_rsc" isleaf="$path{'@isleaf'}">  
  59.                 <handler name="onclick">  
  60.                     canvas.selecteditem =this.datapath;   
  61.                 handler>  
  62.             tree>  
  63.         tree>  
  64.         <scrollbar/>  
  65.     view>    
  66. canvas>  

你可能感兴趣的:(Scheme,XML)