你可以试试这个,
我们需要将 List dataProvider 的 XML 结构更改为 XMLList,以便我们只能显示项目列表,因此我们需要在其间添加 XML 元素。
您可以访问 CODE 属性,例如list.selectedItem.@CODE.toString()
<?xml version="1.0" encoding="utf-8"?><s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"> `<fx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.controls.Alert;
import spark.events.IndexChangeEvent;
[Bindable]
private var xml:XML = <data>
<list>
<GENERAL _index="0" DESCRIPTION="DEAD TIME" CODE="D" _count="1"/>
<REQUEST>
<PARAMETERS>
<page>db/ocr_valid_opr_category.xsl,db/sql.xsl</page>
<maj_cd>COC</maj_cd>
</PARAMETERS>
</REQUEST>
</list>
<list>
<GENERAL _index="1" DESCRIPTION="ENOUGH TIME" CODE="E" _count="2"/>
<REQUEST>
<PARAMETERS>
<page>db/ocr_valid_opr_category.xsl,db/sql.xsl</page>
<maj_cd>COC</maj_cd>
</PARAMETERS>
</REQUEST>
</list>
</data>;
protected function list_changeHandler(event:IndexChangeEvent):void
{
Alert.show(list.selectedItem.@CODE.toString());
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:List id="list" labelField="@DESCRIPTION" dataProvider="{new XMLListCollection(XMLList(xml.list.GENERAL))}"
change="list_changeHandler(event)"/>
</s:WindowedApplication>