gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:57:19 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com