簡體   English   中英

結合自定義組件值

[英]Binding custom components values

我已經使用一些容器和TileList構建了一個自定義組件。 現在,當我在主Flex應用程序中實例化該組件時,我想獲取用戶單擊的tileList中所選項目的值。 換句話說,每次用戶單擊tileList中的項目時,我希望它將所選值分配給主flex應用程序中的全局應用程序變量。 任何想法如何做到這一點?

下面是一種可以收聽TileList.selectedItem更改的方法。 我建議不要將其放在全局變量中,盡管如果必須的話,可以使用諸如ModelLocator之類的模式來實現。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical">

    <mx:Script>
        <![CDATA[

            [Bindable] public var selectedItem:Object;

        ]]>
    </mx:Script>

    <mx:Binding source="listTile.selectedItem" destination="selectedItem"/> 

    <mx:Label text="{ selectedItem }"/>

    <mx:TileList
        id="listTile"
        width="400"
        height="300"
        dataProvider="{ ['A','B','C'] }"/>

</mx:Application>

暫無
暫無

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

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