This is a migrated thread and some comments may be shown as answers.

ListView item template example

1 Answer 77 Views
NativeScript Insiders
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ian
Top achievements
Rank 1
Ian asked on 15 Jan 2015, 01:45 PM
Hi,
Is there any documentation or example code explaining how to populate a ListView using an item template? I'm interested in a code-only approach (ie. no XML) for now.

Thanks, Ian

1 Answer, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 16 Jan 2015, 07:45 AM
Hello Ian,

Here is an example:
var pages = require("ui/page");
var listViewDef = require("ui/list-view");
function createPage() {
    var listView = new listViewDef.ListView();
    listView.items = [{ MyProp: 1 }, { MyProp: 2 }, { MyProp: 3 }, { MyProp: 4 }, { MyProp: 5 }];
    listView.itemTemplate = "<StackPanel><Label text='{{ MyProp }}'></StackPanel>";
    var page = new pages.Page();
    page.content = listView;
    return page;
}
exports.createPage = createPage;


Regards,
Vlad
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
NativeScript Insiders
Asked by
Ian
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or