Fill table with text from json

Hi,
I have a json from an api and want to create from this a table.
I have created my table with the corresponding cells. But I have now the problem to fill the table wit text. If I try to iterate over the cells, rows or columns i have everytime the problem that I can’t iterate because its a object. Also something like myTable.cell[2] doesn’t work to select the second cell or column etc.
Is there any best practise to fill the table with text?

Cheers

Gonna need to see code examples to help here; although it sounds like a vanilla JS issue rather than UXP.

1 Like

You are talking about the InDesign DOM, not JSON, correct?

Most InDesign objects are probably XPath or something based objects, not iterable. To make it easier to iterate, change them to static array like this. Then you can use map, filter, and other useful features.

const cellsArray = myTable.cells.everyItem().getElements() ;

I expect that myTable.cell[2] would work if changed as follows.

myTable.cells[2] ; // cell**s**
1 Like

@sttk3 thanks your code with

.everyItem().getElements()

makes it really easier.
Oh man I hate theese dumb mistakes like missing the plural s :smiley: .

@Timothy_Bennett your right it seems the vanilla js solution from sttk3 makes easier for me.

3 Likes