0
什麼是不同的方法來篩選和分配XML數據 到控件。我的應用程序得到顯示,當我這樣做使用 數組和循環?應用程序變得非常慢?
什麼是不同的方法來篩選和分配XML數據 到控件。我的應用程序得到顯示,當我這樣做使用 數組和循環?應用程序變得非常慢?
希望這會有所幫助。今後試着對你的問題做更具體的描述。
使用for循環通過XML的節點進行迭代,如下所示:
var total:Number = 0;
for each (var property:XML in myXML.item)
{
var q:int = Number([email protected]);
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));
可以使用括號operators--(和)--to過濾元件具有特定元素名稱或屬性值。考慮下面的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")[email protected] 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 。
循環前過濾數據。 – 2010-02-09 19:38:24