可能是一个新手问题,但在查看'net之后,仍然无法找到答案...我有一个像这样的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());
并将'name'节点绑定到下拉列表的标签字段
<s:DropDownList id="s_poolnumber" dataProvider="{poolMenu}" labelField="name"></s:DropDownList>
但是如何将id属性添加为下拉菜单的“数据”字段,以便在选择项目时返回该字段?
我应该创建一个使用@id属性作为“数据”值来源的自定义组件吗? (我也尝试添加一个可能有所帮助的节点,但不幸的是,这也不起作用......)
感谢 彼得
答案 0 :(得分:4)
稍后传递整个对象并获取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>