【问题标题】:Appcelerator Titanium Alloy: How to store data on a ScrollableView to use in click eventAppcelerator Titanium Alloy:如何在 ScrollableView 上存储数据以在点击事件中使用
【发布时间】:2014-03-06 16:00:58
【问题描述】:

我有一个 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} 的值存储在此视图中,以便当我单击/点击它时,我可以使用它打开一个新控制器,并将该值作为参数传递?

【问题讨论】:

    标签: javascript titanium appcelerator titanium-alloy


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多