<mx:XML id="xmlSource">
<node label="grandFather" state="unchecked">
<node label="Father" state="unchecked">
<node label="son" state="unchecked">
<node label="1001" state="unchecked">
<node label="100101" state="unchecked">
</node>
</node>
</node>
</node>
<node label="Uncle" state="unchecked">
<node label="son" state="unchecked">
<node label="1001" state="unchecked">
<node label="100101" state="unchecked">
</node>
</node>
</node>
</node>
<node label="Aunt" state="unchecked">
........省略
</node>
</node>
</mx:XML>
如何循环xml判定state="checked"项的lable
我觉得得要递归,可具体不知道如何实现,请高手指教
10 个解决方案
#1
Debug的时候看看 result的变量
#2
大概就是这样
xml.*.elements("node").(attribute("state")=="unchecked")
没测试
这样返回是个xmllist
xml.*.elements("node").(attribute("state")=="unchecked")
没测试
这样返回是个xmllist
#3
高手,快出现吧,急用!!!!
#4
哎?我被无视了?
#5
不好意思,今天试试
#6
谢谢,帮助,不过,不是做不出想要结果
#7
等待高手出现
#8
楼主试试这个
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:XML id="xmlSource">
<node label="grandFather" state="unchecked">
<node label="Father" state="unchecked">
<node label="son" state="unchecked">
<node label="1001" state="unchecked">
<node label="100101" state="unchecked">
</node>
</node>
</node>
</node>
<node label="Uncle3" state="unchecked">
<node label="son2" state="unchecked">
<node label="1002" state="unchecked">
<node label="100102" state="unchecked">
</node>
</node>
</node>
</node>
<node label="Uncle3" state="unchecked">
<node label="son3" state="unchecked">
<node label="1003" state="unchecked">
<node label="100103" state="checked">
</node>
</node>
</node>
</node>
</node>
</mx:XML>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
private function onClick():void{
var xmlList:XMLList = xmlSource.children();
findChecked(xmlList);
}
private function findChecked(xmlList:XMLList):void{
for(var i:int =0;i<xmlList.length();i++){
if(xmlList[i].@state.toString()== "checked"){
Alert.show(xmlList[i].@label.toString());
break;
}else{
if(xmlList[i].hasComplexContent()){
findChecked(xmlList[i].children());
}
}
}
}
]]>
</mx:Script>
<mx:Button label="test" click="onClick()"/>
</mx:WindowedApplication>
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:XML id="xmlSource">
<node label="grandFather" state="unchecked">
<node label="Father" state="unchecked">
<node label="son" state="unchecked">
<node label="1001" state="unchecked">
<node label="100101" state="unchecked">
</node>
</node>
</node>
</node>
<node label="Uncle3" state="unchecked">
<node label="son2" state="unchecked">
<node label="1002" state="unchecked">
<node label="100102" state="unchecked">
</node>
</node>
</node>
</node>
<node label="Uncle3" state="unchecked">
<node label="son3" state="unchecked">
<node label="1003" state="unchecked">
<node label="100103" state="checked">
</node>
</node>
</node>
</node>
</node>
</mx:XML>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
private function onClick():void{
var xmlList:XMLList = xmlSource.children();
findChecked(xmlList);
}
private function findChecked(xmlList:XMLList):void{
for(var i:int =0;i<xmlList.length();i++){
if(xmlList[i].@state.toString()== "checked"){
Alert.show(xmlList[i].@label.toString());
break;
}else{
if(xmlList[i].hasComplexContent()){
findChecked(xmlList[i].children());
}
}
}
}
]]>
</mx:Script>
<mx:Button label="test" click="onClick()"/>
</mx:WindowedApplication>
#9
楼上的hasComplexContent()是什么函数,使用报错
#10
hasComplexContent()是检查是否有复杂函数。
不好意思,搞定了
很感谢楼上的
不好意思,搞定了
很感谢楼上的
#1
Debug的时候看看 result的变量
#2
大概就是这样
xml.*.elements("node").(attribute("state")=="unchecked")
没测试
这样返回是个xmllist
xml.*.elements("node").(attribute("state")=="unchecked")
没测试
这样返回是个xmllist
#3
高手,快出现吧,急用!!!!
#4
哎?我被无视了?
#5
不好意思,今天试试
#6
谢谢,帮助,不过,不是做不出想要结果
#7
等待高手出现
#8
楼主试试这个
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:XML id="xmlSource">
<node label="grandFather" state="unchecked">
<node label="Father" state="unchecked">
<node label="son" state="unchecked">
<node label="1001" state="unchecked">
<node label="100101" state="unchecked">
</node>
</node>
</node>
</node>
<node label="Uncle3" state="unchecked">
<node label="son2" state="unchecked">
<node label="1002" state="unchecked">
<node label="100102" state="unchecked">
</node>
</node>
</node>
</node>
<node label="Uncle3" state="unchecked">
<node label="son3" state="unchecked">
<node label="1003" state="unchecked">
<node label="100103" state="checked">
</node>
</node>
</node>
</node>
</node>
</mx:XML>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
private function onClick():void{
var xmlList:XMLList = xmlSource.children();
findChecked(xmlList);
}
private function findChecked(xmlList:XMLList):void{
for(var i:int =0;i<xmlList.length();i++){
if(xmlList[i].@state.toString()== "checked"){
Alert.show(xmlList[i].@label.toString());
break;
}else{
if(xmlList[i].hasComplexContent()){
findChecked(xmlList[i].children());
}
}
}
}
]]>
</mx:Script>
<mx:Button label="test" click="onClick()"/>
</mx:WindowedApplication>
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:XML id="xmlSource">
<node label="grandFather" state="unchecked">
<node label="Father" state="unchecked">
<node label="son" state="unchecked">
<node label="1001" state="unchecked">
<node label="100101" state="unchecked">
</node>
</node>
</node>
</node>
<node label="Uncle3" state="unchecked">
<node label="son2" state="unchecked">
<node label="1002" state="unchecked">
<node label="100102" state="unchecked">
</node>
</node>
</node>
</node>
<node label="Uncle3" state="unchecked">
<node label="son3" state="unchecked">
<node label="1003" state="unchecked">
<node label="100103" state="checked">
</node>
</node>
</node>
</node>
</node>
</mx:XML>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
private function onClick():void{
var xmlList:XMLList = xmlSource.children();
findChecked(xmlList);
}
private function findChecked(xmlList:XMLList):void{
for(var i:int =0;i<xmlList.length();i++){
if(xmlList[i].@state.toString()== "checked"){
Alert.show(xmlList[i].@label.toString());
break;
}else{
if(xmlList[i].hasComplexContent()){
findChecked(xmlList[i].children());
}
}
}
}
]]>
</mx:Script>
<mx:Button label="test" click="onClick()"/>
</mx:WindowedApplication>
#9
楼上的hasComplexContent()是什么函数,使用报错
#10
hasComplexContent()是检查是否有复杂函数。
不好意思,搞定了
很感谢楼上的
不好意思,搞定了
很感谢楼上的