I’ve added a couple of buttons, inside a ListView, and I’m having an issue with the binding.
<ListView row="1" items="{{ items }}" itemTap="{{ onListViewItemTap }}" class="menuListView" id="listView">
<ListView.itemTemplate class="combo-list-item">
<GridLayout columns="*, auto, auto" rows="30, auto" class="{{ listItemClass }}" >
<Label row="0" text="{{ displayName }}" textWrap="true" class="item-name" />
<Label row="1" text="{{ ingredients }}" textWrap="true" class="menu-ingredients"/>
<StackLayout row="0" col="2" colSpan="2" rowSpan="2" orientation="horizontal" class="stepper-container-combo">
<Button text=" - " tap="{{ subtractQuantity }}" class="stepper-button-combo"/>
<Label text=" 0 " class="stepper-spacer"/>
<Button text=" + " tap="{{ $parents['ListView'].addQuantity }}" class="stepper-button-combo"/>
</StackLayout>
</GridLayout>
</ListView.itemTemplate>
</ListView>
After some research, I’ve added a tap event like this
tap="{{ $parents[‘ListView’].addQuantity }}"
and this nows get triggered, and in the addQuantity() function the “this” correspond to the “item” object, which is one of the elements of the items="{{ items }}" array that the list is binded to.
My question is: how do I access the viewModel instance from inside my addQuantity() function when the button is tapped, so that I can update the overall quantity and other elements that are outside the listview, and are binded to the viewModel instance.
Any ideas?
Thank you!