@rgbvision/nativescript-indexed-repeater
为 Repeater UI 组件添加获取项目索引的能力
npm i --save @rgbvision/nativescript-indexed-repeater

@rgbvision/nativescript-indexed-repeater

为 Repeater UI 组件添加获取项目索引的能力。

可用于 itemTemplateSelector 或项目的事件处理器中。

安装

ns plugin add @rgbvision/nativescript-indexed-repeater

用法

XML

<ir:IndexedRepeater items="{{ items }}">
<ir:IndexedRepeater.itemsLayout>
<StackLayout orientation="vertical"/>
</ir:IndexedRepeater.itemsLayout>
<ir:IndexedRepeater.itemTemplate>
<Label text="{{ title }}" margin="10" tap="onItemTap"/>
</ir:IndexedRepeater.itemTemplate>
</ir:IndexedRepeater>

确保在 Page 元素上包含 xmlns:ir="@rgbvision/nativescript-indexed-repeater"

TypeScript

export function onItemTap(event: ItemEventData) {
const itemData = event.view.bindingContext;
console.log(`Item index: ${itemData.index}`);
}

警告

插件覆盖了 bindingContext.index 的值。