问题描述
我有一个scrollableview,它在每个子视图中有一些图像和标签.但是,我想为每个项目存储一个id值,以便我可以在onclick事件中使用它.此ID可以用于查询数据库或打开新的控制器所传递的值.
我想在视图上添加一个属性,以存储我的ID,如此
<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中我想做这样的事情:
function carouselItemClick(event) { var selectedItemID = event.source.itemID; // get the ID from the view clicked var view = Alloy.createController("episode", itemID).getView(); }
在我的函数上面,我试图找到itemID属性,但它不存在.
如何存储此视图上{the_id}的值,以便在单击/点击它时,我可以使用它来打开一个作为参数传递的值的新控制器?
推荐答案
event.source将是您实际单独单独的标签或图像.在子图像和标签上设置touchEnabled="false",您的代码应按预期工作.
问题描述
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?
推荐答案
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.