【发布时间】:2016-12-11 02:22:36
【问题描述】:
我有一个旋转了 -90 度的 ListView,它的 ListItem 旋转了 90 度,内置在 Alloy Titanium 中。
每个ListItem都有一个header Label和一个content TableView,TableView数据是动态的。
这是我的 index.xml:
<Alloy>
<Window>
<ListView id="view" defaultItemTemplate="item">
<Templates>
<ItemTemplate id="item" name="item">
<View id="view" bindId="view">
<View class="header">
<Label class="title" bindId="title"/>
<Label class="subtitle" bindId="subtitle"/>
<Label class="desc" bindId="desc"/>
<View class="border"/>
</View>
<TableView class="content" bindId="content"/>
</View>
</ItemTemplate>
</Templates>
<ListSection/>
</ListView>
</Window>
</Alloy>
我正在像这样设置每个 TableView 数据:
var items = [];
items.push({
properties: {
backgroundColor: "#fff",
width: config.height,
height: config.row
},
title: {
text: "title"
},
content: {
data: rows //TableViewRow's array
}
});
$.view.sections[0].setItems(items);
问题是当我想获取点击行的 id 时。
这是我的 itemclick 事件(item index 和 tableview 数据):
$.view.addEventListener("itemclick", function(e) {
console.log("clicked on item: " + e.itemIndex);
var item = $.view.sections[0].getItemAt(e.itemIndex);
_.map(item.content.data || [], function(row) {
console.log(row);
row = null;
});
});
有什么方法可以获取点击行的索引?
我尝试将相同的事件添加到所有这些对象属性中,但仍然没有成功:
item.click
item.onclick
item.properties.click
item.properties.onclick
item.content.click
item.content.onclick
item.content.properties.click
item.content.properties.onclick
item.events.click
item.events.onclick
item.properties.events.click
item.properties.events.onclick
item.content.events.click
item.content.events.onclick
item.content.properties.events.click
item.content.properties.events.onclick
我也尝试将事件侦听器添加到所有行
【问题讨论】:
-
作为一种解决方法,我用 ScrollView 替换了 TableView,有 30 个内部视图,每个视图都具有像 data["view" + index] 一样的 bindId 并且所有标签都被推送到 data["view" + index] 子数组
标签: javascript listview events tableview appcelerator