Problems with displaying ForLoop

I’m trying to have things displayed on a page with a ForLoop but I’m not really sure how to get it on the page. This is my first time using Velo so I’m currently overwhelmed with all the information, and don’t know what some words mean and can’t really understand what it’s explaining to me. Long story short, I have a ForLoop collecting data from an API that successfully shows in the console (using console.log(userName); ) but I am unsure how to display it on the page using $w, or if I have to use repeaters, or even how to use repeaters. I have tried to do $w(‘text91’).text = userName; but it only showed the latest result fetched, my guess is because it displayed all of them one by one then stopped at the last one. So what I’m asking is how to display all the results it fetches?

Where is your code?
Where is the mentioned CONSOLE-LOG?
Where do you fetch from?
How do you fetch?

If you want to get some good answers, then you first should describe your issue a little bit more and give more details on it.

Ok, here it is.


Hopefully this helps.

This is also what the preview looks like in case you wanted to see that as well.


As you can see it only shows the most recently joined member in the text box.

@laoandrei
I asume you want to have all the user-names in a kind of list or even a table or repeater, right?

This part here is the important one…

I have tried to do $w(‘text91’).text = userName; but it only showed the latest result fetched, my guess is because it displayed all of them one by one then stopped at the last one
Yes i see it the same way, the loop stops and you just see the last user-name.

What you will need to have all of them to be shown, is an ARRAY which will collect all the user-names first and then you could push that ARRAY for example to a TABLE or REPEATER.

This would be the structure, how it should look like…

[
  {
    "_id": "1",
    "firstName": "John",
    "lastName": "Doe",
    "image": "http://someImageUrl/john.jpg"
  },
  {
    "_id": "2",
    "firstName": "Jane",
    "lastName": "Doe",
    "image": "http://someImageUrl/jane.jpg"
  }
]

That means…

  1. Generating an ARRAY…
let myArray = [ ]
  1. pushing new Value to the generated new array…
myArray.push({"User": userName})
  1. At the end your new array —> “myArray” looks like that…
[
  {"User": "rob45ca1"},
  {"User": "Owensaurus"},
  {"User": "samlot"},
  {"User": "cole_porter"},
  {"User": "Goldcraft_911"},
]

Now you should be ready to push this data to a table or repeater.

Good luck and happy coding. :wink:

@russian-dima Thanks for all your very helpful tips! These helped a lot and now I am running my code problem-free. Two thumbs up from me.

@laoandrei No problem. Good luck :wink: