【问题标题】:titanuum mobile xmlmarkup events钛移动 xml 标记事件
【发布时间】:2013-09-10 00:17:21
【问题描述】:

从 actionscript (flex) 迁移到 Titan,我正在尝试使用 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);
}

这只会产生一个错误,我仍然不知道点击了什么图片。

任何帮助都会很棒..

谢谢迈克

【问题讨论】:

    标签: templates events mobile titanium


    【解决方案1】:

    您查看过Alloy Quick Start 吗?我想你的很多问题都可以在那里得到解答。

    无论如何,对于 ListViews,您不能在模板中的项目中添加事件侦听器,它只是一个模板而不是屏幕上的实际事物(目前),refer here, and look at the alloy section.

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

    【讨论】:

    • 嗨 Josiah,是的,javascrip 在它的控制器中,我确实浏览了文档,但它没有涵盖一些项目(这是开始的)我会试一试,但我仍然会需要弄清楚哪些 listItem 获得了点击以及如何引用该 ListItem 中的控制。再次感谢
    • itemClick 事件通过了部分,点击的项目编号,check it out here!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多