1

アクション スクリプト (フレックス) からチタンに移行し、xml マークアップを試しています。私が持っているのは、ドキュメントから拾ったテンプレートです

<ItemTemplate name="template">
                    <ImageView left="0" bindId="pic" id="icon" />
                    <Label bindId="info" id="title"/>
                </ItemTemplate>

            </Templates>

私の質問は、誰かが写真またはリスト項目自体をクリックした場合、イベントをどのように処理するかです。xmlマークアップを介して?では、テンプレート内のコントロール ラップをどのように参照しますか?

私が試してみました

<ImageView left="0" bindId="pic" id="icon" onclick="doClick()" />


function doClick(e) {

    alert($.info.text);
}

これはエラーを生成するだけで、どの写真がクリックされたのかまだわかりません。

どんな助けでも素晴らしいでしょう..

ありがとうマイク

4

1 に答える 1

0

Alloyクイックスタートをチェックアウトしましたか? あなたの質問の多くはそこで答えられると思います。

とにかく、ListViews の場合、テンプレート内のアイテムにイベント リスナーを追加することはできません。これは単なるテンプレートであり、(まだ) 画面上の実際のものではありません。ここを参照し、合金のセクションを参照してください。

itemclick代わりに、ListView 自体にイベント リスナーが必要です。XML マークアップがどのようなものかを示す簡単な例については、以下の を確認してください。

    <ListView id="listView" defaultItemTemplate="template" onitemclick="yourEvent" >

        <!-- The Templates tag sets the ListView's templates property -->

        <Templates>

            <!-- Define your item templates within the Templates tags or use the
            Require tag to include a view that only contains an ItemTemplate -->

            <ItemTemplate name="template">
                <ImageView bindId="pic" id="icon" />
                <Label bindId="info" id="title" />
                <Label bindId="es_info" id="subtitle" />
            </ItemTemplate>

        </Templates>
        <ListSection headerTitle="Fruit / Frutas">

            <!-- You can specify any ListItem or ListDataItem properties in ListItem -->

            <!-- Specify data to bind to the item template with inline attributes
            defined as <bindId>:<Ti.UI.Component.property> -->

            <ListItem info:text="Apple" es_info:text="Manzana" pic:image="/apple.png" />
            <ListItem info:text="Banana" es_info:text="Banana" pic:image="/banana.png" />
        </ListSection>
    </ListView>

また、XML マークアップ ファイルではなく、コントローラ ファイルに JavaScript を含める必要があります。*.js には、*.xml であるビューの背後にある JavaScript があります。

于 2013-09-10T13:10:27.570 に答える