簡體   English   中英

使用ArrayCollection dataProvider訪問ComboBox的數據

[英]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;

編輯

或從附加到ComboBoxmx.events.ListEvent.CHANGE處理程序中:

event.target.selectedItem.GroupID

編輯

嗯,代碼格式已更新,更易於閱讀。 我看到您正在使用close事件,並將一個名為selectedItem的變量設置為ComboBoxselectedIndex屬性。 您可以更改它,以便變量selectedItem實際上引用ComboBoxselectedItem屬性,如下所示:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM