簡體   English   中英

在Tree UIComponent FLEX 4.6中獲取所選項目的名稱

[英]Getting name of selected item in Tree UIComponent FLEX 4.6

這是我第二天使用FLEX和AS 3.0,所以我對此很陌生。 我試圖獲取樹組件中所選項目的值,在這種情況下,它只是一個名稱。 下面是我創建的樹。 樹內容已通過編程方式填充有名為“ cat”的數組。 樹被填充得很好,但我不知道如何獲取當前所選項目的名稱。

<mx:Tree id="category_tree" x="10" y="80" width="160" height="169" showRoot="true" dataProvider="{cat}" labelField="name">

我已經使用了selectedItem.toString()函數,但這似乎只返回對象的類型而不是值。 目前,它返回“對象對象”。在我的腳本中,我有...

category_tree.selectedItem.toString();

任何幫助,將不勝感激。 預先感謝您的寶貴時間。

您可以將更改事件添加到樹中,並使用類似於以下內容的回調:

 private function changeEvt(event:Event):void {
        var lableData:*;
        var label:String;

        if (event.currentTarget.selectedItem.@data) {
           labelData = event.currentTarget.selectedItem.@data;
        }

        label = event.currentTarget.selectedItem.@label; 
     }
 }

或直接訪問值

category_tree.selectedItem.@label;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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