Appcelerator钛合金:如何在ScrollableView上存储数据以在单击事件中使用 [英] Appcelerator Titanium Alloy: How to store data on a ScrollableView to use in click event

查看:93
本文介绍了Appcelerator钛合金:如何在ScrollableView上存储数据以在单击事件中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ScrollableView,每个子视图中都有一些图像和标签.但是,我想为每个项目存储一个ID值,以便可以在onClick事件中使用它.此ID可用于查询数据库或打开一个新控制器,将值传递给它.

I have a ScrollableView, which has some images and labels inside each child view. However, I would like to store a ID value for each item, so that I can use it inside an onClick event. This ID could the be used to query the database or open up a new controller the value passed in.

我曾考虑过要在视图上添加一个属性来存储我的ID,就像这样

I thought about adding an attribute on the view, to store my ID, like so

<ScrollableView dataCollection="videos" id="mainCarousel">
    <View onClick="carouselItemClick" itemID="{the_id}">
        <ImageView image="{episode_img_cached}"></ImageView>                
        <Label text="{title}" id="mainCarouselTitle"></Label>              
        <Label text="{series_txt}" id="mainCarouselSeriesDetails"></Label>    
        <Label text="{episode_txt}" id="mainCarouselEpDetails"></Label>
    </View>
</ScrollableView>

在我的carouselItemClick中,我想做这样的事情:

In my carouselItemClick I'd like to do something like this:

function carouselItemClick(event) {
    var selectedItemID = event.source.itemID; // get the ID from the view clicked
    var view = Alloy.createController("episode", itemID).getView();
}

在上面的函数中,我试图找到该itemID属性,但它不存在.

In my function above, I've tried to find that itemID attribute, but it's not there.

如何在此视图中存储{the_id}的值,以便在单击/轻击它时可以使用它打开一个新控制器,并将该值作为参数传递给该控制器?

How can I store the value of {the_id} on this view, so that when I click/tap on it, I can use it to open up a new controller with that value passed as an argument?

推荐答案

event.source将是您实际单击的标签或图像.在子图像和标签上设置touchEnabled="false",您的代码应该可以正常工作.

event.source will be the label or image that you actually clicked on. Set touchEnabled="false" on the child image and labels, and your code should work as expected.

这篇关于Appcelerator钛合金:如何在ScrollableView上存储数据以在单击事件中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆