2009-11-10 2 views
0
[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를 원합니다.ArrayCollection dataProvider를 사용하여 ComboBox의 데이터에 액세스

선택한 그룹의 실제 그룹 ID를 얻으려면 어떻게해야합니까?

답변

2

당신과 같이 그것을 얻을 수있을 것입니다 :

grpLst.selectedItem.GroupID; 

편집

또는에서를 ComboBox에 부착 된 mx.events.ListEvent.CHANGE 핸들러 내 :

event.target.selectedItem.GroupID 

편집

아, 코드 형식이 업데이트되어 읽기 쉽습니다. close 이벤트를 사용하고 selectedItem이라는 변수를 selectedIndex 속성 인 ComboBox으로 설정하는 것을 확인합니다.

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'] 
+0

공공 기능 groupListRH 변수 selectedItem 실제로 ComboBox 그래서 등의 selectedItem propterty을 참조하도록 당신은 그것을 바꿀 수 (이벤트 : ResultEvent) : void {groupsList = event.result ArrayCollection;} public function show (이벤트) : void {selectedItem = (event.target as ComboBox) .selectedIndex; 이런 식으로되지 않습니다 ... 어떻게 groupId (정확한 ID는 원격 개체를 통해 arraycollection에 들어가고있다) 얻을 수 있습니다 선택한 GroupName ... ?? –

+0

해당 코드로 질문에 편집을 추가하거나 새 질문을 만드십시오. 저는 컴파일러가 아니기 때문에 시각적으로 형식화 된 코드 만 구문 분석 할 수 있습니다. ;-) –

관련 문제