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

发布于 2024-09-30 00:37:08 字数 1561 浏览 0 评论 0原文

可能是一个新手问题,但在浏览网络后,仍然找不到答案...我有一个像这样的 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());

并将“名称”节点绑定到下拉列表的标签字段,

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

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

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

谢谢 彼得

probably a newbie question, but after looking through the 'net, still cannot find an answer... I have an XML object like this:

<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>

I load this file to an XML variable:

var poolMenuXML:XMLList = questionpoolsXML.questionpools;
poolMenu = new XMLListCollection(poolMenuXML.children());

and bind the 'name' node to a dropdown's label field

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

but how to add the id attribute as the 'data' field of the dropdown so when an item is selected, it returns that field?

Shall I create a custom component that uses the @id attribute as the source of the 'data' values? (I've also tried to add a node thinking that might help but unfortunately that does not work either...)

thanks
peter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说谎友 2024-10-07 00:37:08

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

Pass whole object and fetch id attribute later. See onDropDownListChange method

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文