Apache flex 如何将xml节点值绑定到Flex中的下拉数据字段?

Apache flex 如何将xml节点值绑定到Flex中的下拉数据字段?,apache-flex,drop-down-menu,dataprovider,Apache Flex,Drop Down Menu,Dataprovider,可能是一个新手问题,但在浏览“网络”后,仍然找不到答案。。。我有这样一个XML对象: <questionpools> <questionpool id="1"> <name>Sample test bank</name> <description>This is a Sample test bank description</description> <createdate>2010.10.10&l

可能是一个新手问题,但在浏览“网络”后,仍然找不到答案。。。我有这样一个XML对象:

<questionpools>
 <questionpool id="1">
  <name>Sample test bank</name>
  <description>This is a Sample test bank description</description>
  <createdate>2010.10.10</createdate>
  <moddate>2010.10.11</moddate>
  <createdby>testuser</createdby>
  <modby>testuser</modby>
</questionpool>
<questionpool id="2">
  <name>alme</name>
  <description>newpool</description>
  <createdate>2010.10.31</createdate>
  <moddate>2010.10.31</moddate>
  <createdby>testuser</createdby>
  <modby>testuser</modby>
</questionpool>
<questionpool id="9">
  <name>pool_new</name>
  <description>newpool</description>
  <createdate>2010.10.31</createdate>
  <moddate>2010.10.31</moddate>
  <createdby>testuser</createdby>
  <modby>testuser</modby>
</questionpool>
并将“name”节点绑定到下拉列表的标签字段

<s:DropDownList id="s_poolnumber" dataProvider="{poolMenu}" labelField="name"></s:DropDownList>

但是,如何将id属性添加为下拉列表的“数据”字段,以便在选择某个项目时返回该字段

我应该创建一个自定义组件,使用@id属性作为“数据”值的源吗?(我还尝试添加一个节点,认为这可能会有所帮助,但不幸的是,这也不起作用……)

谢谢
peter

稍后传递整个对象并获取id属性。请参见onDropDownListChange方法

<?xml version="1.0" encoding="utf-8"?>
<s:Application 
    minHeight="600"
    minWidth="955"
    creationComplete="application1_creationCompleteHandler(event)"
    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.events.FlexEvent;

            import spark.events.IndexChangeEvent;

            [Bindable] private var poolMenu:XMLListCollection;

            private var questionpoolsXML:XML = <questionpools>
                    <questionpool id="1">
                        <name>Sample test bank</name>
                        <description>This is a Sample test bank description</description>
                        <createdate>2010.10.10</createdate>
                        <moddate>2010.10.11</moddate>
                        <createdby>testuser</createdby>
                        <modby>testuser</modby>
                    </questionpool>
                    <questionpool id="2">
                        <name>alme</name>
                        <description>newpool</description>
                        <createdate>2010.10.31</createdate>
                        <moddate>2010.10.31</moddate>
                        <createdby>testuser</createdby>
                        <modby>testuser</modby>
                    </questionpool>
                    <questionpool id="9">
                        <name>pool_new</name>
                        <description>newpool</description>
                        <createdate>2010.10.31</createdate>
                        <moddate>2010.10.31</moddate>
                        <createdby>testuser</createdby>
                        <modby>testuser</modby>
                    </questionpool>
                </questionpools>;

            private function application1_creationCompleteHandler(event:FlexEvent):void
            {
                poolMenu = new XMLListCollection(questionpoolsXML.children());
            }

            private function onDropDownListChange(event:IndexChangeEvent):void
            {
                trace(s_poolnumber.selectedItem.@id);
            }
        ]]>
    </fx:Script>

    <s:DropDownList id="s_poolnumber"
        dataProvider="{poolMenu}"
        labelField="name"
        change="onDropDownListChange(event)"/>
</s:Application>

样本测试库
这是一个样本测试库描述
2010.10.10
2010.10.11
测试用户
测试用户
阿尔姆
纽普尔
2010.10.31
2010.10.31
测试用户
测试用户
新泳池
纽普尔
2010.10.31
2010.10.31
测试用户
测试用户
;
私有函数应用程序1\u creationCompleteHandler(事件:FlexEvent):无效
{
poolMenu=newXMLListCollection(questionpoolsXML.children());
}
私有函数onDropDownListChange(事件:IndexChangeEvent):void
{
跟踪(s_poolnumber.selectedItem@id);
}
]]>
谢谢,它很管用!(现在我只需要找到一种方法来过滤XMLListCollection以设置下拉值-相同的内容,反之亦然)
<?xml version="1.0" encoding="utf-8"?>
<s:Application 
    minHeight="600"
    minWidth="955"
    creationComplete="application1_creationCompleteHandler(event)"
    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.events.FlexEvent;

            import spark.events.IndexChangeEvent;

            [Bindable] private var poolMenu:XMLListCollection;

            private var questionpoolsXML:XML = <questionpools>
                    <questionpool id="1">
                        <name>Sample test bank</name>
                        <description>This is a Sample test bank description</description>
                        <createdate>2010.10.10</createdate>
                        <moddate>2010.10.11</moddate>
                        <createdby>testuser</createdby>
                        <modby>testuser</modby>
                    </questionpool>
                    <questionpool id="2">
                        <name>alme</name>
                        <description>newpool</description>
                        <createdate>2010.10.31</createdate>
                        <moddate>2010.10.31</moddate>
                        <createdby>testuser</createdby>
                        <modby>testuser</modby>
                    </questionpool>
                    <questionpool id="9">
                        <name>pool_new</name>
                        <description>newpool</description>
                        <createdate>2010.10.31</createdate>
                        <moddate>2010.10.31</moddate>
                        <createdby>testuser</createdby>
                        <modby>testuser</modby>
                    </questionpool>
                </questionpools>;

            private function application1_creationCompleteHandler(event:FlexEvent):void
            {
                poolMenu = new XMLListCollection(questionpoolsXML.children());
            }

            private function onDropDownListChange(event:IndexChangeEvent):void
            {
                trace(s_poolnumber.selectedItem.@id);
            }
        ]]>
    </fx:Script>

    <s:DropDownList id="s_poolnumber"
        dataProvider="{poolMenu}"
        labelField="name"
        change="onDropDownListChange(event)"/>
</s:Application>