[英]flex - getting data from an xml list
我有一个简单的 xml 像这样:
<root Name="Bob" isImployed="true">
<customer Name="Bob" id="12345">was addressed in the shopping mall</customer>
<Job-title>Insurance</Job-title>
<experience>15</experience>
<Question1 question="how much do you make?">35000</Question1>
<Question2 question="do you get a yearly bonus?">5000</Question2>
<Question3 question="would you be interested in our weekly plan?">yes</Question3>
</root>
我创建了一个包含数据的 XMLList:
var mylist:XMLList;
我想对所有问题进行 go (不止 question1、question2 和 question3)。 其中一些包含数字(薪水,奖金),而另一些则不包含。 我正在寻找一种方法来 go 在整个列表中,查询答案是否是数字,如果是 - 获取数字。 (并用它做一些计算)。 我怎样才能做到这一点?
谢谢!
这个循环应该 go 到 xml 并读取所有问题的值并获得数字:
for each (var question:XML in mylist..*) {
if (question.hasOwnProperty("@question") && !isNaN(question.valueOf())) {
var value:int = question.valueOf();
// do calclulations on value
}
}
这应该为您提供所需的所有部件。
<mx:XML id="someXML" xmlns="">
<root Name="Bob" isImployed="true">
<customer Name="Bob" id="12345">was addressed in the shopping mall</customer>
<Job-title>Insurance</Job-title>
<experience>15</experience>
<Question1 question="how much do you make?">35000</Question1>
<Question2 question="do you get a yearly bonus?">5000</Question2>
<Question3 question="would you be interested in our weekly plan?">yes</Question3>
</root>
</mx:XML>
<mx:List dataProvider="{someXML..@question}">
<mx:itemRenderer>
<mx:Component>
<mx:VBox>
<mx:Label text="Question: {data}" fontWeight="bold" />
<mx:Label text="{XML(data).parent()}" />
<mx:Label text="Is Number: {isNaN(XML(data).parent())?'No':'Yes'}" />
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:List>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.