申请得很慢?

时间:2010-02-09 18:22:57

标签: actionscript-3 flex flex3

过滤和分配XML数据有哪些不同的方法 控制。我的应用程序在我使用时显示 数组和循环??

1 个答案:

答案 0 :(得分:0)

希望这会有所帮助。在将来,请尝试对您的问题进行更具体的说明。

使用for循环迭代XML的节点,如下所示:

var total:Number = 0;
for each (var property:XML in myXML.item)
{
    var q:int = Number(property.@quantity);
    var p:Number = Number(property.price);
    var itemTotal:Number = q * p;
    total += itemTotal;
    trace(q + " " + property.menuName + " $" + itemTotal.toFixed(2))
}
trace("Total: $", total.toFixed(2));

您可以使用括号运算符 - (和) - 过滤具有特定元素名称或属性值的元素。请考虑以下XML对象:

var x:XML = 
    <employeeList>
        <employee id="347">
            <lastName>Zmed</lastName>
            <firstName>Sue</firstName>
            <position>Data analyst</position>
        </employee>
        <employee id="348">
            <lastName>McGee</lastName>
            <firstName>Chuck</firstName>
            <position>Jr. data analyst</position>
        </employee>
    </employeeList>

以下表达式均有效:

x.employee.(lastName ==
   "McGee")--This is the second employee
   node. 

x.employee.(lastName ==
   "McGee").firstName--This is the   
   firstName property of the second   
   employee node. 

x.employee.(lastName
   == "McGee").@id--This is the value of    the id attribute of the second   
   employee node. 

x.employee.(@id ==
   347)--The first employee node.

x.employee.(@id ==
   347).lastName--This is the lastName  
   property of the first employee node.

x.employee.(@id > 300)--This is an
   XMLList with both employee   
   properties.

x.employee.(position.toString().search("analyst")
      > -1)--This is an XMLList with both position properties.

参见http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_04.html 了解更多信息。