Appcelerator Titanium Alloy: How to store data on a ScrollableView to use in click event

廉价感情. 提交于 2019-12-11 21:51:44

问题


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.

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>

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();
}

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

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?


回答1:


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.



来源:https://stackoverflow.com/questions/22229632/appcelerator-titanium-alloy-how-to-store-data-on-a-scrollableview-to-use-in-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!