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

查看:14
本文介绍了Appcelerator Titanium Alloy:如何在 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 Titanium Alloy:如何在 ScrollableView 上存储数据以在点击事件中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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