今天在官方提供的例子上看到这东西,贴出来。
从employeesE4X.xml这个文件中,查询部门接点为finance的部门,然后显示在List控件中。
先看看这个xml文档。
<? xml version = "1.0" encoding = "utf-8" ?> |
< employees > |
< employee dept = "sales" > |
< id >1</ id > |
< firstName >Bob</ firstName > |
< lastName >Smith</ lastName > |
< officePhone ext = "143" >(415)555-1111</ officePhone > |
</ employee > |
< employee dept = "research" > |
< id >2</ id > |
< firstName >John</ firstName > |
< lastName >Doe</ lastName > |
< officePhone ext = "243" >(408)555-2222</ officePhone > |
</ employee > |
< employee dept = "finance" > |
< id >3</ id > |
< firstName >John</ firstName > |
< lastName >Smith</ lastName > |
< officePhone ext = "002" >(408)324-6432</ officePhone > |
</ employee > |
< employee dept = "sales" > |
< id >4</ id > |
< firstName >Jane</ firstName > |
< lastName >Riley</ lastName > |
< officePhone ext = "211" >(415)123-1234</ officePhone > |
</ employee > |
< employee dept = "finance" > |
< id >5</ id > |
< firstName >Arthur</ firstName > |
< lastName >Dent</ lastName > |
< officePhone ext = "014" >(415)555-1212</ officePhone > |
</ employee > |
< employee dept = "sales" > |
< id >6</ id > |
< firstName >Bruce</ firstName > |
< lastName >Chizen</ lastName > |
< officePhone ext = "051" >(408)234-1253</ officePhone > |
</ employee > |
</ employees > |
再看看具体是如何操作的。重点是searchQuery这个查询方法。
<? xml version = "1.0" encoding = "utf-8" ?> |
<!-- |
//////////////////////////////////////////////////////////////////////////////// |
// ADOBE SYSTEMS INCORPORATED |
// Copyright 2007 Adobe Systems Incorporated |
// All Rights Reserved. |
// |
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the |
// terms of the Adobe license agreement accompanying it. If you have received this file from a |
// source other than Adobe, then your use, modification, or distribution of it requires the prior |
// written permission of Adobe. |
//////////////////////////////////////////////////////////////////////////////// |
--> |
< mx:Application xmlns:mx = "<A href=" http://www.adobe.com/2006/mxml">http://www.adobe.com/2006/mxml</ A >" |
layout="absolute" |
backgroundAlpha="0" backgroundColor="#FFFFFF"> |
|
< mx:Script > |
<![CDATA[ |
import mx.collections.ArrayCollection; |
|
[Bindable] |
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:Script > |
|
< mx:XML id = "employees" source = "employeesE4X.xml" /> |
< mx:List dataProvider = "{empDept}" creationComplete = "searchQuery()" top = "20" left = "20" width = "75%" horizontalCenter = "0" editable = "false" /> |
</ mx:Application > |