Reputation: 6177
I have a listview (code below), in the listview there is a Button
with a tap
event. I am trying to bind the function from my view-model code. The basic flow is the same as the typescript template for nativescript apps. However, this doesn't work because it's not a property of the items bound to the listview. I don't want to move the binded function outside of the view-model. I can't be the only crazy person doing something like this :P
<ListView.itemTemplate>
<GridLayout backgroundImage="{{ whatever }}" rows="auto, auto, auto" columns="70, *, auto">
<Label row="0" col="1" text="{{ title }}" color="{{ whatever }}" class="feed-title" textWrap="true" />
<Button text="" row="0" col="2" color="{{ whatever }}" tap="{{ moreOptionsTap }}" class="ionicon" />
</GridLayout>
</ListView.itemTemplate>
Ignore the incorrect listview template, I stripped out a bunch of stuff to make this readable.
Upvotes: 2
Views: 773
Reputation: 6177
Well forget the question, don't know why I didn't think to try what I was already doing inside the ListView on some other components. Docs here: https://docs.nativescript.org/core-concepts/data-binding#binding-to-a-parent-binding-context
tap="{{ $parents['ListView'].moreOptionsTap }}"
Upvotes: 4