nativescript Displaying data as list (using Repeater, ListView or *ngFor for {N}+Angular-2 apps) Using Repeater with Callbacks (JavaScript)


Example

page.js

var context = {
items: [
        {id: 1, name: "Foo"},
        {id: 2, name: "Bar"},
        {id: 3, name: "Joe"}
    ]
}

exports.loaded = function(args){
    var page = args.object;
    page.bindingContext = context;
}

exports.showEntry = function(args){
    // select the tapped entry without passing an index or anything like that
    var selectedEntry = args.view.bindingContext;
    console.log(selectedEntry.id + " " + selectedEntry.name);
}

page.xml

<Repeater items="{{ items }}" >
    
    <Repeater.itemTemplate>
        <Label text="{{ name }}" tap="showEntry" />
    </Repeater.itemTemplate>
    
</Repeater>