0

I am trying to use NativeScript's ListView tag and I am apparently not understanding how to use it.

In my HTML template page, I have the following snippet

<ListView items="{{someArray}}">
    <ListView.template>
         <Label text="{{name}}"></Label>
    </ListView.template>
</ListView>

My array has a single (eventually it will have more) object in it that is formatted like this:

array = [
    {
        name: 'A name',
        match: false,
    }
];

When I compile this, I get the following showing up on my emulator

screenshot

Where that [object Object] being displayed is the array that I am passing into items={{}}. I tried passing JSON.stringify(someArray) to the items just to see what would happen and it displayed every character on its own line - which makes sense, a string is just an array of characters. I can't figure out how to actually loop through the array.

I based the code on https://docs.nativescript.org/cookbook/ui/list-view#define-the-listview-itemtemplate-property but I apparently don't understand what I am reading because this is not desired behavior.

I know I could render a WebView but I would rather understand what I am doing wrong.

I tried this on a test page, where I didn't have anything but the ListView on the page and I still got the same result..

1 Answer 1

2

I was reading the wrong documentation and not using Angular 2 syntax

<ListView col="1" row="1" [items]="someArray">
     <template let-item="item">
           <Label [text]="item.name"></Label>
     </template>
</ListView>

Fixed it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.