Flex XML问题
xml对象如下<folderstate="schrodinger"label="公司"isBranch="true"><folderstate="schrodinger"...
xml对象如下
<folder state="schrodinger" label="公司" isBranch="true">
<folder state="schrodinger" isBranch="true" label="物流事业部">
<folder state="unchecked" isBranch="false" label="wl1"/>
<folder state="unchecked" isBranch="false" label="wl2"/>
<folder state="unchecked" isBranch="false" label="wl3"/>
<folder state="unchecked" isBranch="false" label="wl4"/>
<folder state="unchecked" isBranch="false" label="wl5"/>
<folder state="unchecked" isBranch="false" label="wl6"/>
<folder state="unchecked" isBranch="false" label="wl7"/>
<folder state="checked" isBranch="false" label="wl8"/>
<folder state="checked" isBranch="false" label="wl9"/>
</folder>
<folder state="schrodinger" isBranch="true" label="浙江分公司">
<folder state="checked" isBranch="false" label="fen1"/>
<folder state="unchecked" isBranch="false" label="fen2"/>
</folder>
<folder state="schrodinger" isBranch="true" label="技术中心">
<folder state="schrodinger" isBranch="true" label="产品一部">
<folder state="checked" isBranch="false" label="11"/>
<folder state="unchecked" isBranch="false" label="12"/>
<folder state="unchecked" isBranch="false" label="13"/>
</folder>
<folder state="unchecked" isBranch="true" label="产品二部">
<folder state="unchecked" isBranch="false" label="21"/>
<folder state="unchecked" isBranch="false" label="22"/>
<folder state="unchecked" isBranch="false" label="23"/>
</folder>
<folder state="unchecked" isBranch="true" label="产品三部">
<folder state="unchecked" isBranch="false" label="31"/>
<folder state="unchecked" isBranch="false" label="32"/>
<folder state="unchecked" isBranch="false" label="33"/>
</folder>
<folder state="unchecked" isBranch="true" label="研发部">
<folder state="unchecked" isBranch="false" label="41"/>
<folder state="unchecked" isBranch="false" label="42"/>
<folder state="unchecked" isBranch="false" label="43"/>
</folder>
</folder>
</folder>
现在想根据state=="checked"以及isBranch=="false"这两个条件取到label的值
这里我希望得到
wl8,wl9,fen1,11这几个值
我用xml.folder.folder.(attribute("state")=="checked"&&attribute("isBranch")=="false")+"\n"+
xml.folder.folder.folder.(attribute("state")=="checked"&&attribute("isBranch")=="false")取时当最里面那一层的只有一个是state是"checked"的时候取不到值,超过一个就可以,奇怪
解决了加分一定
非常感谢“vim888”的回答,现在已经能够拿到我选中的那些值了。
不过xml..folder.(@state=="checked" && @isBranch=="false")取到的是节点
trace(xml..folder.(@state=="checked" && @isBranch=="false"));打印出来是这样的
<folder state="checked" isBranch="false" label="fen1"/>
<folder state="checked" isBranch="false" label="fen2"/>
<folder state="checked" isBranch="false" label="21"/>
<folder state="checked" isBranch="false" label="22"/>
<folder state="checked" isBranch="false" label="23"/>
<folder state="checked" isBranch="false" label="31"/>
我现在把上面的那些拼成一个XML,看下面代码
var checkednode:String;
checkednode = "<node>\n"+
xml..folder.(@state=="checked" && @isBranch=="false")+
"</node>";
var checkedXML:XML = new XML(checkednode);
trace(checkedXML.folder.@label);
这样打印出来的结果是这样的
fen1fen221222331能不能做到这样:fen1,fen2,21,22,23,31,即每个label中间加个分隔符,万分感谢! 展开
<folder state="schrodinger" label="公司" isBranch="true">
<folder state="schrodinger" isBranch="true" label="物流事业部">
<folder state="unchecked" isBranch="false" label="wl1"/>
<folder state="unchecked" isBranch="false" label="wl2"/>
<folder state="unchecked" isBranch="false" label="wl3"/>
<folder state="unchecked" isBranch="false" label="wl4"/>
<folder state="unchecked" isBranch="false" label="wl5"/>
<folder state="unchecked" isBranch="false" label="wl6"/>
<folder state="unchecked" isBranch="false" label="wl7"/>
<folder state="checked" isBranch="false" label="wl8"/>
<folder state="checked" isBranch="false" label="wl9"/>
</folder>
<folder state="schrodinger" isBranch="true" label="浙江分公司">
<folder state="checked" isBranch="false" label="fen1"/>
<folder state="unchecked" isBranch="false" label="fen2"/>
</folder>
<folder state="schrodinger" isBranch="true" label="技术中心">
<folder state="schrodinger" isBranch="true" label="产品一部">
<folder state="checked" isBranch="false" label="11"/>
<folder state="unchecked" isBranch="false" label="12"/>
<folder state="unchecked" isBranch="false" label="13"/>
</folder>
<folder state="unchecked" isBranch="true" label="产品二部">
<folder state="unchecked" isBranch="false" label="21"/>
<folder state="unchecked" isBranch="false" label="22"/>
<folder state="unchecked" isBranch="false" label="23"/>
</folder>
<folder state="unchecked" isBranch="true" label="产品三部">
<folder state="unchecked" isBranch="false" label="31"/>
<folder state="unchecked" isBranch="false" label="32"/>
<folder state="unchecked" isBranch="false" label="33"/>
</folder>
<folder state="unchecked" isBranch="true" label="研发部">
<folder state="unchecked" isBranch="false" label="41"/>
<folder state="unchecked" isBranch="false" label="42"/>
<folder state="unchecked" isBranch="false" label="43"/>
</folder>
</folder>
</folder>
现在想根据state=="checked"以及isBranch=="false"这两个条件取到label的值
这里我希望得到
wl8,wl9,fen1,11这几个值
我用xml.folder.folder.(attribute("state")=="checked"&&attribute("isBranch")=="false")+"\n"+
xml.folder.folder.folder.(attribute("state")=="checked"&&attribute("isBranch")=="false")取时当最里面那一层的只有一个是state是"checked"的时候取不到值,超过一个就可以,奇怪
解决了加分一定
非常感谢“vim888”的回答,现在已经能够拿到我选中的那些值了。
不过xml..folder.(@state=="checked" && @isBranch=="false")取到的是节点
trace(xml..folder.(@state=="checked" && @isBranch=="false"));打印出来是这样的
<folder state="checked" isBranch="false" label="fen1"/>
<folder state="checked" isBranch="false" label="fen2"/>
<folder state="checked" isBranch="false" label="21"/>
<folder state="checked" isBranch="false" label="22"/>
<folder state="checked" isBranch="false" label="23"/>
<folder state="checked" isBranch="false" label="31"/>
我现在把上面的那些拼成一个XML,看下面代码
var checkednode:String;
checkednode = "<node>\n"+
xml..folder.(@state=="checked" && @isBranch=="false")+
"</node>";
var checkedXML:XML = new XML(checkednode);
trace(checkedXML.folder.@label);
这样打印出来的结果是这样的
fen1fen221222331能不能做到这样:fen1,fen2,21,22,23,31,即每个label中间加个分隔符,万分感谢! 展开
1个回答
展开全部
用xml..folder.(@state=="checked" && @isBranch=="false")这句来查询看看。
..表示匹配里面所有的folder节点。
xml..folder.(@state=="checked" && @isBranch=="false")返回的是XMLList对象的,所以可以这样:
var tmp:XMLList=xml..folder.(@state=="checked" && @isBranch=="false");
var str:String="";
for(var i:int=0;i<tmp.length();i++){
if(str==""){
str=tmp[i].@label;
}else{
str+=","+tmp[i].@label;
}
}
..表示匹配里面所有的folder节点。
xml..folder.(@state=="checked" && @isBranch=="false")返回的是XMLList对象的,所以可以这样:
var tmp:XMLList=xml..folder.(@state=="checked" && @isBranch=="false");
var str:String="";
for(var i:int=0;i<tmp.length();i++){
if(str==""){
str=tmp[i].@label;
}else{
str+=","+tmp[i].@label;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询