Access Items Size and Other attributes of Model inside ListView



I want to access items size inside ListView. Also I want know how to access other attributes of Model inside a ListView. Following is Example:

<ListView items="{{ items }}" row="1" separatorColor="blue" itemTemplateSelector="$index">
            <Label textWrap="true" textAlignment="center" marginTop="20dpi">
                            <span text="Item "/>
                            <span text="{{ $index+1 }}"/>
                            <span text=" Of "/>
                            <span text="{{ items.length }}"/>

I face problem accesing items.length.



Use $parent.items.length.

More info:


Thanks @manojdcoder for the link. I checked on playground using $parent.items.length but no luck.


In my case I used label without formatted text, when accessing multiple levels above, you have use $parents['ComponentName'].


Thanks @manojdcoder. It works just fine.


Though the screen is rendered correctly I get following error on console when I use $parents[‘ListView’].items.length:

JS: Binding: Property: ‘items’ is invalid or does not exist. SourceProperty: ‘$parents[‘ListView’].items.length’

I have items initialised to empty array in the constructor.


If you want to eliminate the error log, then use

 <span text="{{ $parents['ListView'].items, $parents['ListView'].items.length }}" />


This is better. Thanks @manojdcoder :slight_smile: