PricingBlog

Binding to Variable on Repeat Item

  • stockton_f-1186534861343834153

    Stockton

    2 years ago

    I have an array of objects that I want to provide a form on to update values.

    In other words, the form in the repeat item will be used to update the record in the database.

    I'm using Supabase.

    Each record has an ID.

    When the items load, I want the input fields to show the current value (if any).

    But the user should be able to update the value for the given repeat record.

    I tried to Bind to variable piece but that would bind each repeated item to the same variable which won't work because then if I'm updating the second item it could inherit the binding from the first item...
    1186534862497259552-image.png
  • stockton_f-1186541387836035132

    Stockton

    2 years ago

    Okay I think I got it actually... gotta think in components 😉

    Steps:
    1. On parent page use an API to get all the records
    2. Repat item on a component for each record in the API. The component is the card that has the form and the record details.
    3. Pass in the record details as an attribute to the component
    5. In the component bind the data to variables.
    6. Create an API in the component to update the record in supabase
  • andreasmoller-1186565270244966450

    Andreas Møller

    2 years ago

    Yes that sounds like a good solution
    💃1
  • rscott-1198904768203083788

    Bishop

    1 year ago

    oh this is the question i just asked. the component/attribute is what abstracts it enough for it to work i guess

    the variable in each instance of the component is separate from every other one i guess
  • andreasmoller-1198905084281618442

    Andreas Møller

    1 year ago

    Yes each instance of a component has its own variables and apis which are completely isolated from the outside world.
  • andreasmoller-1199019532791062698

    Andreas Møller

    1 year ago

    Did you get it to work?
  • rscott-1199234642407075920

    Bishop

    1 year ago

    Yes this seems to be working thanks for asking.