Flex tree 遍历

========================================================
//第一级
				var tXML:XML=mytree.selectedItem as XML;//前提是创建树的时候已指定selectedIndex=0
				Alert.show("11:"+tXML.@name);
                //第二种方法:第一级
				var tXML:Object=mytree.dataProvider;
				Alert.show(tXML.toString());
				var xmlList:XMLList=XMLList(tXML);
				Alert.show(xmlList.@name);
===========================================================
				//遍历第二级
				var tXML:Object=mytree.dataProvider;
				for each(var p:XML in tXML.children()){
				Alert.show("ss:"+p.@name);
				}
					//第二种方法:遍历第二级
				var tXML:Object=mytree.dataProvider;
				var xmlList:XMLList=tXML.elements("node");
				var collection:XMLListCollection=new XMLListCollection(xmlList);
				for each(var p:XML in collection){
				Alert.show("22:"+p.@name);
				}
========================================================
//				//遍历第三级
				var tXML:Object=mytree.dataProvider;
				for each(var p:XML in tXML.children()){
					for each(var q:XML in p.children()){
					Alert.show("q:"+q.@name);
					}
				}
//第二种方法:直接遍历第三级:
				var tXML:Object=mytree.dataProvider;
				for each(var p:XML in tXML.children().children()){
						Alert.show("33:"+p.@name);
				}

//第三种方法:遍历第三级
				var tXML:Object=mytree.dataProvider;
				var xmlList:XMLList=tXML.elements("node").elements("node");
				var collection:XMLListCollection=new XMLListCollection(xmlList);
				for(var i=0;i<collection.length;i++){
					Alert.show("33:"+collection[i].@name);
				}
				//第四种方法:遍历第三级
				var tXML:Object=mytree.dataProvider;
				var xmlList:XMLList=tXML.elements("node");
				var collection:XMLListCollection=new XMLListCollection(xmlList);
				for(var i=0;i<collection.length;i++){
					for each( var p:XML in collection[i].node){
						Alert.show(p.@selected+"-333-"+p.@name);
					}
				}
==========================================================

你可能感兴趣的:(Flex)