I ma following a course on pluralsight and I have encountered an odd problem. My list view is only showing the first element and nothing else. This is odd and i've used list views without problem before so I'm not sure where the error is coming from.
Layout:
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
loaded="pageLoaded">
<GridLayout rows="auto, *">
<!-- Header -->
<StackLayout cssClass="page-header">
<Label text="Header" cssClass="page-title bold" horizontalAlignment="center" margin="15"/>
</StackLayout>
<!-- Sessions Views -->
<GridLayout rows="auto, *" row="1">
<ListView items="{{ sessions }}">
<ListView.itemTemplate>
<Label text="{{ title }}"/>
</ListView.itemTemplate>
</ListView>
</GridLayout>
</GridLayout>
</Page>
Typescript:
import { EventData, Observable } from "data/observable";
import { Page } from "ui/page";
var page: Page;
var tempSessions = [
{
id: '0',
title: "Stuff"
},
{
id: '1',
title: "Stuffly"
},
{
id: '2',
title: "Stufferrs"
},
{
id: '3',
title: "Event 4"
}
];
export function pageLoaded(args: EventData){
console.log(JSON.stringify(tempSessions));
page = <Page>args.object;
page.bindingContext = new Observable({
sessions: tempSessions
});
}
I suspected that the first list item was completely filling the gridLayout however placing a border around it reveals that it is not.
GridLayout
the first argument for itsrows
property is auto and will not display theListView
correctly. You should change it to*
, for example<GridLayout rows="*, auto" row="1">
or to specify the ListViewheight
. You should also specify therow
for the ListView. – Fallal