我可以轻松地将小部件添加到 CollectionView,但我似乎无法添加多个小部件类型。我正在尝试添加 2 个 TextView。这是我到目前为止得到的,它只输出了 firstName 两次。(这在操场上运行)
另外,是否可以向每个 TextView 添加事件?喜欢:
.on('tap', () => {
我确实在 Collection View 上看到了.on('select',
工作原理,但我想将事件添加到每个单独的 TextView
谢谢。
// Create a collection view, initialize its cells and fill it with items
const {CollectionView, Composite, ImageView, TextView, ui} = require('tabris');
let people = [
['Bob', 'Smith',],
['Fred', 'Jones'],
['James', 'Mackay'],
].map(([firstName, lastName]) => ({firstName, lastName}));
new CollectionView({
left: 0, top: 0, right: 0, bottom: 0,
itemCount: people.length,
cellHeight: 56,
createCell: () => {
let cell = new Composite();
new TextView({
left: 30, top: 10,
alignment: 'left'
})
.appendTo(cell);
let txvLastName = new TextView({
left: 50, top: 25,
alignment: 'right'
})
.appendTo(cell);
return cell;
},
updateCell: (cell, index) => {
let person = people[index];
cell.apply({
TextView: {text: person.firstName},
txvLastName: {text: person.lastName},
});
}
}).on('select', ({index}) => console.log('selected', people[index].firstName))
.appendTo(ui.contentView);