我在獲取用戶在我的移動Flex應用程序中選擇的項目的值時遇到問題。當我從列表中選擇一個項目時,我將該項目放入ArrayCollection中。但是當我檢查值(trace())時,該值是[object Object],我似乎無法訪問該對象的實際值。下面是我在做什麼:從跟蹤訪問列表中選定項目的值時出現問題
private var selectedPlayers:ArrayCollection = new ArrayCollection();
private var numOfPlayers:int;
...
//check if item is not already in selected players list
if(!selectedPlayers.contains(playerList.selectedItem))
{
//add the selected item to the selected players list
selectedPlayers.addItem(playerList.selectedItem);
numOfPlayers++;
trace("selected Players: " + selectedPlayers);
}
輸出():
選擇玩家:[對象的對象]
非常感謝您的任何意見和見解。
更新:這裏的工作代碼:
[Bindable]
public static var selectedPlayers:ArrayCollection = new ArrayCollection([
{Name: "testname" }]);
...
//check if item is not already in selected players list
if(!selectedPlayers.contains(playerList.selectedItem.PName))
{
//add the selected item to the selected players list
selectedPlayers.addItem({Name: playerList.selectedItem.PName});
numOfPlayers++;
}
你跟蹤整個ArrayCollection的,沒有任何具體的項目,從內它。 – shanethehat
即使我跟蹤(「選定的玩家:」+ selectedPlayers.getItemAt(0))我得到相同的輸出。 – Jordan