2

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="&#xf397;" 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.

1 Answer 1

4

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 }}"
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.