FramerJS, design to code, array loop

64 views Asked by At

I've been trying to create a loop via a dummy array on a design list element from the design tab. I see the array is being loaded in the loop. I can't seem to put the list items below each other.

After trying to fix it for a long time, can someone point out what I'm doing wrong?

for title in titleArray
    newItem = titleArray[title] = listItem.copy()
    newItem.y=(newItem.height)*title+58

    newItem.parent= scroll.content
    listItem.parent = scroll.content

https://framer.cloud/QdVJT

1

There are 1 answers

1
Niels On

When iterating over the array, you will get the elements of the array instead of the indexes, to get the index, you can add another variable after a comma:

for title, index in titleArray
    newItem = listItem.copy()
    newItem.y = newItem.height * index
    newItem.selectChild("fieldTitle").text = title

Full example here: https://framer.cloud/BAnEq