Hi everyone, please excuse me while I try to adapt to the visual way…
I want to try and loop through some API data to see if I can find a value. Now in code I would find this realtaivly easy but I cant seem to figure out how to do it the wappler way.
So what I want to do is
Setup a Count Var
Get API data
Loop through data looking for the value increatement count vat by 1 for each item
Once I have found the value return true and exit out of the loop
How would I accomplish this in Wappler? Would this be a server side or a client side (or could it be either)?
You can do this easily in server action.
Set count var using set value step.
Then, after api action, add a repeat action. Inside the repeat action set a condition action to check for the value you want and update the variable using set value.
If you just want the count of number of times a value exists in the API response, you can use where and count formatters in the client side.
If you are not familiar with the terms above, try searching for them in the community and docs. Else, post here again.
Hey @sid thanks for your suggestion earlier. What I am strugglig with on the server action is that it doesnt expand the array of items from the API to search through.
Heres the screenshot of the api from the server action you can see how it wont let me expand the items returned from the API.
Here’s the screenshot of the API from the client side
I am assuming what I want to do is do something like this with the repeat expression? ‘{{searchdata.data.items[count] .id.videoId==videoid}}’
Edit: I’ve just figure it out while reading another post. If i set the repeat to the API data then it allows me to access the items
The array not expanding might be a bug. @Teodor might be able to explain on this better.
As for the repeat expression, it would just be the searchdata.data.items. Then inside the repeat, the condition step that you add will have the condition like id.videoid == videoid.
Thanks SId, yeah when I set the repeat to the searchdata.data.items that allowed me to view the items and in there and select the videoid. My last question now is there a way to break out of the repeat when the condition is true. Thank you so much for all your help