[英]Accessing Data of a ComboBox with an ArrayCollection dataProvider
[Bindable]
public var groupsList:ArrayCollection;
public function groupListRH(event:ResultEvent):void
{
groupsList=event.result as ArrayCollection;
}
<mx:ComboBox dataProvider="{groupsList}"
labelField="groupName"
id="grpLst" width="150"
prompt="Select one group "
close="selectedItem=ComboBox(event.target).selectedIndex"
focusIn="init();" />
<mx:LinkButton label="New Group" id="creatgrp" click="addNewGroup();"/>
這里是從RemoteObject獲取組數組(groupName,GroupID每行),並顯示在ComboBox中。 我正在選擇selectedIndex為0、1、2、3的組,但是我希望我的對應組名的groupID可以帶到客戶端。
如何實際獲得所選組的groupId?
您應該能夠像這樣獲得它:
grpLst.selectedItem.GroupID;
編輯
或從附加到ComboBox
的mx.events.ListEvent.CHANGE
處理程序中:
event.target.selectedItem.GroupID
編輯
嗯,代碼格式已更新,更易於閱讀。 我看到您正在使用close事件,並將一個名為selectedItem
的變量設置為ComboBox
的selectedIndex
屬性。 您可以更改它,以便變量selectedItem
實際上引用ComboBox
的selectedItem
屬性,如下所示:
selectedItem=(event.target as ComboBox).selectedIndex;
// Then get the GroupID from the selectedItem
selectedGroupID = selectedItem.GroupID
或者只是使用索引從dataProvider
獲取數據:
selectedIndex=(event.target as ComboBox).selectedIndex;
// Then get the GroupID from the dataProvider
selectedGroupID = groupList[selectedIndex]['GroupID']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.