PricingBlog

sort / filter array to show hide

  • nathandh.-1269592237994672139

    nathandh

    1 year ago

    Let’s say I get an API response with content tagged in 5 different categories, and I add 5 buttons in the UI to show / hide based on user selection. What’s the preferred way to do this?

    Would each button be tied to a filter function, that then returns a slice of the response, and then hides everything else on the page? Thanks for helping me think through this.
  • Tod-1269592239475265556

    Tod

    1 year ago

    Great energy @nathandh! Your continuous contribution to the toddle Community just made you advance to Community Level 1!
  • lucasg-1269663042254409820

    Lucas G

    1 year ago

    I would create one function that filters the array based on the value of the variable
  • Which would be linked to the array of buttons
  • nathandh.-1269842151085310038

    nathandh

    1 year ago

    OK that makes sense. How would you handle display though on the canvas?
  • lucasg-1269854986045755532

    Lucas G

    1 year ago

    What do you mean by that?
  • nathandh.-1269864442397593660

    nathandh

    1 year ago

    Meaning when I tie the click event of the button to the array filter, how do I update the repeating list of items?
  • lucasg-1269867372060086273

    Lucas G

    1 year ago

    The list can be repeated over a variable
    👍1
  • The buttons update that variable
    🙌🏼1
  • neville9288-1277586205810364492

    Neville

    1 year ago

    @nathandh I have a similar requirement - were you able to resolve this?
  • nathandh.-1277816504078831626

    nathandh

    1 year ago

    Yes, it works as described above
  • neville9288-1278328379250311279

    Neville

    1 year ago

    I got it working thanks