apache-flex - 如何将 xml 节点值绑定(bind)到 Flex 中的下拉数据字段?

标签 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</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>

我将此文件加载到 XML 变量中:
var poolMenuXML:XMLList = questionpoolsXML.questionpools;
poolMenu = new XMLListCollection(poolMenuXML.children());

并将“名称”节点绑定(bind)到下拉列表的标签字段
<s:DropDownList id="s_poolnumber" dataProvider="{poolMenu}" labelField="name"></s:DropDownList>

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

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

谢谢
彼得

最佳答案

稍后传递整个对象并获取 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>

关于apache-flex - 如何将 xml 节点值绑定(bind)到 Flex 中的下拉数据字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4081791/

相关文章:

ruby-on-rails - 如何创建一个网络服务

apache-flex - Flex Builder的开源替代品?

c# - 如何在客户端和服务器端使用 selectedIndexChanged 下拉列表

javascript - 如何打开带有焦点 jquery 事件的下拉列表 <select>?

jquery - 使用 JSON 数据填充下拉菜单

php - Yii2 : how to cache active data provider?

java - DataProvider 不适用于外部整数

actionscript-3 - 如何将 .as 文件列表编译为单个 .swf?

iOS adobe airrelease构建错误,应用程序无法启动

javascript - 在 React-Admin 中显示一个数组