1

从 actionscript (flex) 移动到钛,我正在尝试使用 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

你检查过合金快速入门吗?我想你的很多问题都可以在那里得到解答。

无论如何,对于 ListViews,您不能将事件侦听器添加到模板中的项目,它只是一个模板而不是屏幕上的实际事物(还),请参阅此处,并查看合金部分。

相反,您需要itemclickListView 本身的事件侦听器。检查下面的 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>

此外,您需要将任何 JavaScript 放在控制器文件中,而不是在 XML 标记文件中。*.js 在视图后面有 javascript,即 *.xml。

于 2013-09-10T13:10:27.570 回答