Flex -如何发送Flex下拉列表中选定项的ID到服务器


Flex - How to send the ID of the selected item of a Flex DropDownList to the server?

我正在使用FlashBuilder 4.5 for PHP。我有一个简单的MySQL表字段{tID, tName}。

我能够在Flex表单中填充下拉列表,如下所示。下拉列表毫无问题地显示了人员的姓名:

<s:Form defaultButton="{button}">
 <s:FormItem label="myList: ">
  <s:DropDownList id="dropDownList" creationComplete="dropDownList_creationCompleteHandler(event)" >
   <s:AsyncListView list="{getPeopleResult.lastResult}"/>
  </s:DropDownList>
 </s:FormItem>
 <s:Button id="button" label="Submit"click="button_clickHandler(event)"/>
</s:Form>

在我的button_clickHandler函数中,我想从下拉列表中获得选中项的ID:

protected function button_clickHandler(event:MouseEvent):void
{
 person.tID=dropDownList.selectedItem as int;
 createpersonResult.token=personservice.createperson(person);
}
上面的

不起作用。我将感激任何帮助!

您可能需要这个或类似的:

person.tID=dropDownList.selectedItem.tID as int;

dropDownList.selectedItem的直接值可能是"[Object]" -很可能是person对象,字段为tIDtName

这是我的猜测基于代码,我可以看到到目前为止…:)

您应该始终使用parseInt()或parseFloat()进行从Number到String的转换。你的问题就解决了。