Cécil
Cécil

Reputation: 25

How to use the index of a JavaScript loop in a thymeleaf iteration?

I would like to use the index of this JavaScript loop to iterate my thymeleaf integration. For example:

for(let i=1; i<8; i++){
    /*[# th:each="temp : ${arrayListTemperature[ i ] }"]*/
        {x: new Date[(${temp})]},
    /*[/]*/
}

To get

/*[# th:each="temp : ${arrayListTemperature1}"]*/
    { x: new Date[(${temp})]},
/*[/]*/

Upvotes: 1

Views: 43

Answers (1)

rocambille
rocambille

Reputation: 15976

Your thymeleaf is executed server-side, before the page is send to the browser.

Your JavaScript is executed client-side, after the page is send to the browser.

So what you're asking looks impossible: thymeleaf can't access a value during its execution, while this value will exist after thymeleaf was executed.

Upvotes: 1

Related Questions