PricingDocsAcademy
Bluesky ...
Wed, Dec 11, 10:43 PM

repeat over 2 data sources

  • mossi

    1 month ago

    I have a div that is repeated over an array from an api call. (user creation api). The div shows some user info and repeats it for users created. Once user is created they can create items. I have another api that gets the number of items each user created (gets this from db, based on user ID). In the repeated div I want to also show total number of items created for each user in their own repeated div. How do I do this?
  • Lucas G

    1 month ago

    You should be able to do this with the Size node
  • If you're filtering an array based on user Id, you can pass that array into the node and get a number
  • mossi

    1 month ago

    I figured out that part of it. My issue is that once the div is repated over the first api call, how do it dynamically pass values to the same div from other api calls. i.e. the api call that the repeat is based on outputs an array like user1, user2. And another api call returns another array like user1 total items(= 3 after using Size fx), user2 total items (= 1). Now i want 3 and 1 to be in the repeated div that belongs to user 1 and user 2 respectivly.
  • Tom Ireland

    1 month ago

    Do you receive any kind of user identifier in the second API call? You could use that as a comparison to populate your other element with the total e.g. Get total items where repeat item userid == API call userid. Hard to advise without seeing the setup or understanding the flow from beginning to end.
  • mossi

    1 month ago

    Hi Tom,
    Yes I have userid reference to the same user in both api calls. how do implement the approach you recommanded? do i make a formula?
  • Tom Ireland

    1 month ago

    I'm at work now but can take a look later on. Can you show an example screenshot of the formula you're using for the repeat div and the second API call where you're already setting size to get the total number of items?
  • /attachments/1295184293869391995/1295315149393104947/repeat_div_api.png

    mossi

    1 month ago

    here you go. Plz note in this example, the total items belongs to the user of index 1 (not index 0). The repeate div api call returns all the users in db and userids are returned as we. The second api call returns total items created for a user with a given userid. Same userid reference for any given user is included in both api calls.
  • Tod

    1 month ago

    Great energy @mossi! Your continuous contribution to the toddle Community just made you advance to Community Level 2!
  • Kai

    1 month ago

    hey, just copy the data of api to a variable as an array of the data sent by the api. Then call the second api an add the result to the array. With this you can show them both in same repeat... Hope I understood you correctly...
  • Lucas G

    1 month ago

    You just use the repeated item's Id to filter the array and use size
  • It doesn't change anything and it's fine if it is two different calls that you're using
  • As long as the Id of the repeated item matches
  • /attachments/1295184293869391995/1295468468727975956/Screenshot_2024-10-14_122059.png

    mossi

    1 month ago

    the userids inside data of each index matches but the indexes dont match. For example in the screenshots i provided the 4 indexes of returned data in the screenshot on the right belong to index 1 of the screecshot on the left (which is the array the repeat is based on). here is my div structure; the parent div is repeated over the api with 2 indexes and I want the h3 value to bind with the output of api call with 4 indexes for a given userid dynamically. in this example the value 4 belongs to index 1 of the repeat array.
  • Lucas G

    1 month ago

    Yeah exactly just filter the second one with the userid
  • Index doesn't matter

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.