NativeScript Core

In this article
API Reference
Not finding the help you need?

Repeater

The Repeater widget allows you to display a collection of data, which is present in an array.

const repeaterModule = require("tns-core-modules/ui/repeater");

Basics

The example shows how to define Repeater in the XML and how to load its data.

<Label row="0" text="Binding the Repeater items property to collection" textWrap="true" />
<Button row="1" text="Add new item" tap="onTap" />
<ScrollView row="2">
    <Repeater  id="firstRepeater" items="{{ myItems }}" />
</ScrollView>
<Label row="3" text="Define the Repeater itemTemplate property" textWrap="true" />
<Button row="4" text="Add new item (Second Repeater)" tap="onSecondTap" />
<ScrollView row="5" orientation="horizontal">
    <Repeater items="{{ mySecondItems }}">
        <Repeater.itemsLayout>
            <StackLayout orientation="horizontal" />
        </Repeater.itemsLayout>
        <Repeater.itemTemplate>
            <Label text="{{ $value }}" margin="10" />
        </Repeater.itemTemplate>
    </Repeater>
</ScrollView>

Note: Note, that changing the array after the repeater is shown will not update the UI. You can force-update the UI using the refresh() method.

colors.push("yellow");
// Manually trigger the update so that the new color is shown.
repeater.refresh();

Note: When using ObservableArray the repeater will be automatically updated when items are added or removed form the array.

secondColorsArray.push("yellow");
// The Repeater will be updated automatically.

Improve this document

Demo Source


Code Behind

In the following example is shown, how to create Repeater via Code-behind

<StackLayout id="stackLayoutId">
        <Label text="{{ 'Result: ' + prResult}}" textWrap="true" />

</StackLayout>

Improve this document

Demo Source


API Reference for Repeater Class