Flex Tree以及复选框tree(icon)

原创 2015年07月06日 17:13:52
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"
		   xmlns:views="com.zteits.atms.util.Componment.*"
		   xmlns:controls="com.zteits.atms.component.it.sephiroth.controls.*"
		   width="100%" 
		   height="100%" 
		   borderStyle="none" 
		   creationComplete="myinit()" 
		   layout="absolute">
	<mx:Script source="Sig_Test_mokuai.as"/>
	<mx:RemoteObject id="SigMsgAction"
					 destination="SigMsgAction"
					 fault="faultHandler(event)"
					 showBusyCursor="true">
		<mx:method name="getTestTree" result="processTest(event.result)"/>
		<mx:method name="getTestTree2" result="processTest2(event.result)"/>
	</mx:RemoteObject>
	<mx:HBox width="100%" height="100%">
		<mx:VBox width="30%" height="100%" paddingLeft="5" paddingRight="5" paddingTop="5" paddingBottom="5">
			<mx:VBox width="100%" height="100%">
				<mx:Tree  id="tree1" 
						  width="100%" 
						  height="100%"
						  labelField="@name"
						  showRoot="true"
						  backgroundColor="#FFFFFF"
						  iconFunction="iconfuction"
						  itemClick="treeChanged(event)"
						  >
				</mx:Tree>
			</mx:VBox>
			<mx:HBox width="100%" horizontalAlign="right">
				<mx:Button label="获得树" click="getTree();"/>
			</mx:HBox>	
		</mx:VBox>	
		
		<mx:VBox width="30%" height="100%" paddingLeft="5" paddingRight="5" paddingTop="5" paddingBottom="5">
			<mx:VBox width="100%" height="100%">
				<controls:TreeCheckBox id="tree2" width="100%" height="100%" checkField="@isSelect"
									   itemCheck="onItemCheck(event)" labelField="@name"
									   openItems="{xml.node}"/>
			</mx:VBox>
			<mx:HBox width="100%" horizontalAlign="right">
				<mx:Button label="获得树2" click="getTree2();"/>
			</mx:HBox>	
		</mx:VBox>	
	</mx:HBox>	
</mx:Module>

as

import com.zteits.atms.component.it.sephiroth.renderers.TreecheckboxItemRenderer;
import com.zteits.atms.sig.monitor.vo.NodeForDeviceControl;

import flash.events.Event;

import mx.controls.Alert;
import mx.controls.Tree;
import mx.events.TreeEvent;
import mx.rpc.events.FaultEvent;

var xml:XML= null;

//111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

private function myinit():void
{
}
private function faultHandler(event:FaultEvent):void
{
	Alert.show("fault");
}
////+++++++++++打开root下的树的方法!!!!
//private function processTest(result:Object):void
//{
//	var xmlstr:String=result.toString();
//	xml =new XML(xmlstr);
//	this.tree1.dataProvider=xml;
//	expendAllTree(tree1);
//}
//private function expendAllTree(tree:Tree):void
//{
//	for each (var item:XML in tree.dataProvider)
//	{
//      //可以用@+属性
//		Alert.show(""+item.@name);
//		tree.openItems=item;
//		tree.expandChildrenOf(item, true);
//	}
//}
//+++++++++++++++++++++++打开全部树的方法
private function processTest(result:Object):void
{
	var xmlstr:String=result.toString();
	xml =new XML(xmlstr);
	this.tree1.dataProvider=xml;
	tree1.callLater(expendAllTree);
	//	expendAllTree(tree1);
}

private function expendAllTree():void
{
	tree1.expandChildrenOf(xml, true);
}
private function getTree():void
{
	SigMsgAction.getTestTree("tree1");
}
//点击事件的Event不要忘记!!!
public function treeChanged(event:Event):void {
	
	test();
	try{
		//		var selectedNode:NodeForDeviceControl=Tree(event.target).selectedItem as NodeForDeviceControl;
		
		//		可以+@属性,如果想转化成对象,需要给tree赋值的是这个对象的ArrayCollection
		//		Alert.show(""+Tree(event.target).selectedItem.@leaf);
		var selectedNode:Object=Tree(event.target).selectedItem as Object;
		if(selectedNode.@leaf=="1"){
			Alert.show("yezi");
		}
	}catch (error:Error)
	{
		Alert.show(error.message.toString());
	}
	
}
public function test():void
{
	//   
	Alert.show("-"+(1 << 1 | 2 << 1));  //6
	Alert.show("+"+(1 << 1 & 2 << 1));  //0
	Alert.show("-"+(5|3)+","+(3|5));    //7,7
	Alert.show("+"+(5&3)+","+(3&5));    //1,1
	
	Alert.show("~2:"+(~2));             //-3
}
//111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
//111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

//22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222


private function processTest2(result:Object):void
{
	var xmlstr:String=result.toString();
	xml =new XML(xmlstr);
	this.tree2.dataProvider=xml;
	tree2.callLater(expendAllTree2);
	//	expendAllTree(tree1);
}
private function expendAllTree2():void
{
	tree2.expandChildrenOf(xml, true);
}

private function getTree2():void
{
	SigMsgAction.getTestTree2("tree2");
}

[Embed(source="com/zteits/atms/sig/image/Sig1.png")]
[Bindable]  
public var bule:Class; 
[Embed(source="com/zteits/atms/sig/image/folder.png")]
[Bindable]
public var folder:Class;
private  function iconfuction(event:Object):*{
	if(event.@leaf == 0){
		return folder;
	}else{
		return bule;
	}
}
//点击事件的Event不要忘记!!!
public function treeChanged2(event:Event):void {
	try{
//		var selectedNode:NodeForDeviceControl=Tree(event.target).selectedItem as NodeForDeviceControl;
		
//		可以+@属性,如果想转化成对象,需要给tree赋值的是这个对象的ArrayCollection
//		Alert.show(""+Tree(event.target).selectedItem.@leaf);
		var selectedNode:Object=Tree(event.target).selectedItem as Object;
		if(selectedNode.@leaf=="1"){
//			Alert.show("yezi");
		}
	}catch (error:Error)
	{
		Alert.show(error.message.toString());
	}

}
//需要common包里的as类
private function onItemCheck(event:TreeEvent):void
{
	updateParents(event.item as XML, (event.itemRenderer as TreecheckboxItemRenderer).checkBox.checkState);
	updateChilds(event.item as XML, (event.itemRenderer as TreecheckboxItemRenderer).checkBox.checkState);
}
/**
 * 更新树节点
 */
private function updateParents(item:XML, value:uint):void
{
	var checkValue:String=(value == (1 << 1 | 2 << 1) ? "2" : value == (1 << 1) ? "1" : "0");
	var parentNode:XML=item.parent();
	if (parentNode)
	{
		for each (var x:XML in parentNode.node)
		{
			if (x.@isSelect != checkValue)
			{
				checkValue="2";
			}
		}
		parentNode.@isSelect=checkValue;
		updateParents(parentNode, value);
	}
}
/**
 * 更新树的分支
 */
private function updateChilds(item:XML, value:uint):void
{
	var middle:Boolean=(value & 2 << 1) == (2 << 1);
	var selected:Boolean=(value & 1 << 1) == (1 << 1);
	
	if (item.children().length() > 0 && !middle)
	{
		for each (var x:XML in item.node)
		{
			x.@isSelect=value == (1 << 1 | 2 << 1) ? "2" : value == (1 << 1) ? "1" : "0";
			updateChilds(x, value);
		}
	}
}
//22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
//22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222

java

//-------------------------------------------------------------------------
	public String getTestTree(String conditions) throws Exception
	{
		System.out.println("action--------------");
		org.dom4j.Document doc = null;
        org.dom4j.Element root = null;
        
        doc = org.dom4j.DocumentHelper.createDocument();
        //+++++++root 赋到 doc上
        //=======doc有addElement()
        root = doc.addElement("node");
        
        root.addAttribute("id", "1");
        root.addAttribute("name", "All");
        root.addAttribute("leaf", "0");
        root.addAttribute("age", "100");
        //+++++++创建element,在后面在加到root
        org.dom4j.Element element = DocumentHelper.createElement("node");
        element.addAttribute("id", "11");
        element.addAttribute("name", "lv");
        element.addAttribute("leaf", "1");
        element.addAttribute("age", "25");
        
        org.dom4j.Element element2 = DocumentHelper.createElement("node");
        element2.addAttribute("id", "12");
        element2.addAttribute("name", "gao");
        element2.addAttribute("leaf", "0");
        element2.addAttribute("age", "23");
        
        org.dom4j.Element element21 = DocumentHelper.createElement("node");
        element21.addAttribute("id", "121");
        element21.addAttribute("name", "gao大");
        element21.addAttribute("leaf", "1");
        element21.addAttribute("age", "23");
        
        element2.add(element21);
        
        org.dom4j.Element element22 = DocumentHelper.createElement("node");
        element22.addAttribute("id", "122");
        element22.addAttribute("name", "gao小");
        element22.addAttribute("leaf", "1");
        element22.addAttribute("age", "23");
        
        element2.add(element22);
        //=======root用add(),而不是用addElement()
        root.add(element);
        root.add(element2);
		return doc.asXML();
	}
	//-------------------------------------------------------------------------
		public String getTestTree2(String conditions) throws Exception
		{
			System.out.println("action--------------");
			org.dom4j.Document doc = null;
	        org.dom4j.Element root = null;
	        
	        doc = org.dom4j.DocumentHelper.createDocument();
	        //+++++++root 赋到 doc上
	        //=======doc有addElement()
	        root = doc.addElement("node");
	        
	        root.addAttribute("id", "1");
	        root.addAttribute("name", "All");
	        root.addAttribute("leaf", "0");
	        root.addAttribute("age", "100");
	        root.addAttribute("isSelect", "0");
	        //+++++++创建element,在后面在加到root
	        org.dom4j.Element element = DocumentHelper.createElement("node");
	        element.addAttribute("id", "11");
	        element.addAttribute("name", "lv");
	        element.addAttribute("leaf", "1");
	        element.addAttribute("age", "25");
	        element.addAttribute("isSelect", "0");
	        
	        org.dom4j.Element element2 = DocumentHelper.createElement("node");
	        element2.addAttribute("id", "12");
	        element2.addAttribute("name", "gao");
	        element2.addAttribute("leaf", "0");
	        element2.addAttribute("age", "23");
	        element2.addAttribute("isSelect", "0");
	        
	        org.dom4j.Element element21 = DocumentHelper.createElement("node");
	        element21.addAttribute("id", "121");
	        element21.addAttribute("name", "gao大");
	        element21.addAttribute("leaf", "1");
	        element21.addAttribute("age", "23");
	        element21.addAttribute("isSelect", "0");
	        
	        element2.add(element21);
	        
	        org.dom4j.Element element22 = DocumentHelper.createElement("node");
	        element22.addAttribute("id", "122");
	        element22.addAttribute("name", "gao小");
	        element22.addAttribute("leaf", "1");
	        element22.addAttribute("age", "23");
	        element22.addAttribute("isSelect", "0");
	        
	        element2.add(element22);
	        //=======root用add(),而不是用addElement()
	        root.add(element);
	        root.add(element2);
			return doc.asXML();
		}



 


 

 

 

 

 

Flex之Tree组件(修改图标,加复选框)

一、效果展示 二、mxml文件
  • sssssxh
  • sssssxh
  • 2015年06月18日 14:05
  • 887

tree 复选框

  • 2015年05月06日 23:21
  • 6KB
  • 下载

【JSF】Richfaces复选框树(Checkbox tree)的权限分配的解决方案

【JSF】Richfaces复选框树(Checkbox tree)的权限分配的解决方案 应大家要求,在此帖上效果图: 设计信息系统的时候,往往要设计一套用户管理模块,其中就会牵扯到...

【无事水一发】ExtJS4 Ext.tree.Panel (无限层级)带复选框树勾选(父级子级)联动代码

//原创,转载请注明出处~~//勾选父节点,之下所有子节点自动勾选;反之自动取消子节点勾选(无限层级)//勾选所有子节点,父节点自动勾选;反之自动取消父节点勾选(无限层级)Ext.onReady(fu...

jquery+css+html无限级tree树形菜单(含复选框)

jquery使用,tree树形目录结构,无限级树形目录

Extjs3.4 带复选框的树结构(Tree+checkbox)案例

框架为struts2  1. jsp页面:  Java代码   "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://...

Java中带复选框的树(Java CheckBox Tree)的实现和应用

在使用Java Swing开发UI程序时,很有可能会遇到使用带复选框的树的需求,但是Java Swing并没有提供这个组件,因此如果你有这个需求,你就得自己动手实现带复选框的树。 CheckBoxTr...

extjs tree checkbox 复选框实现 取值 显示

原来做EXTTREE的复选其实很简单! 数据: [{id:'55',text:'节点11',leaf:false,checked:true} checked属性就是控制复选框是否出现...

Java中带复选框的树(Java CheckBox Tree)的实现和应用

在使用Java Swing开发UI程序时,很有可能会遇到使用带复选框的树的需求,但是Java Swing并没有提供这个组件,因此如果你有这个需求,你就得自己动身实现带复选框的树。 CheckBo...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Flex Tree以及复选框tree(icon)
举报原因:
原因补充:

(最多只允许输入30个字)