How to access "$index" value inside listItemTemplate of ListView?


#1
<Page loaded="pageLoaded" class="page" xmlns="http://www.nativescript.org/tns.xsd">

	<ActionBar title="Home" class="action-bar">
	</ActionBar>

	<ListView items="{{ englishAlphabets }}"  itemTemplateSelector="$index">
			<ListView.itemTemplate>
				<Label text="{{ $index +' --> ' + letter }}" textWrap="false" />
				
			</ListView.itemTemplate>
	</ListView>
		
</Page>

Prerequisites:

  1. Elements of array should be Objects . It won’t work with Plain array(. like [1,2,3,4])
  2. Add itemTemplateSelector="$index" in ListView Tag as shown in the code.

Playground Link: ListView Index


#2

@Anand569
That’s really useful. Thanks for sharing a playground demo as well! :heart: