今天在官方提供的例子上看到这东西,贴出来。
从employeesE4X.xml这个文件中,查询部门接点为finance的部门,然后显示在List控件中。
先看看这个xml文档。
<? xml version = "1.0" encoding = "utf-8" ?> |
< firstName >Bob</ firstName > |
< lastName >Smith</ lastName > |
< officePhone ext = "143" >(415)555-1111</ officePhone > |
< employee dept = "research" > |
< firstName >John</ firstName > |
< officePhone ext = "243" >(408)555-2222</ officePhone > |
< employee dept = "finance" > |
< firstName >John</ firstName > |
< lastName >Smith</ lastName > |
< officePhone ext = "002" >(408)324-6432</ officePhone > |
< firstName >Jane</ firstName > |
< lastName >Riley</ lastName > |
< officePhone ext = "211" >(415)123-1234</ officePhone > |
< employee dept = "finance" > |
< firstName >Arthur</ firstName > |
< lastName >Dent</ lastName > |
< officePhone ext = "014" >(415)555-1212</ officePhone > |
< firstName >Bruce</ firstName > |
< lastName >Chizen</ lastName > |
< officePhone ext = "051" >(408)234-1253</ officePhone > |
再看看具体是如何操作的。重点是searchQuery这个查询方法。
<? xml version = "1.0" encoding = "utf-8" ?> |
< mx:Application xmlns:mx = "<A href=" http://www.adobe.com/2006/mxml">http://www.adobe.com/2006/mxml</ A >" |
backgroundAlpha="0" backgroundColor="#FFFFFF"> |
import mx.collections.ArrayCollection; |
private var empDept:ArrayCollection = new ArrayCollection; |
private function searchQuery():void{ |
for each(var xml:XML in employees.employee.(@dept == "finance")) |
empDept.addItem(xml.firstName + " " + xml.lastName + "'s Department is " + <A href="mailto:xml.@dept">xml.@dept</A>); |
< mx:XML id = "employees" source = "employeesE4X.xml" /> |
< mx:List dataProvider = "{empDept}" creationComplete = "searchQuery()" top = "20" left = "20" width = "75%" horizontalCenter = "0" editable = "false" /> |
转载于:https://blog.51cto.com/2771253/524237