【问题标题】:How to use the index of a JavaScript loop in a thymeleaf iteration?如何在 thymeleaf 迭代中使用 JavaScript 循环的索引?
【发布时间】:2020-04-29 08:36:28
【问题描述】:

我想使用这个 JavaScript 循环的索引来迭代我的 thymeleaf 集成。例如:

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

得到

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

【问题讨论】:

    标签: javascript thymeleaf


    【解决方案1】:

    您的 thymeleaf 在服务器端执行,在页面发送到浏览器之前。

    您的 JavaScript 在客户端执行,在页面发送到浏览器之后。

    所以你问的看起来不可能:thymeleaf 在执行期间无法访问一个值,而这个值将在 thymeleaf 执行后存在。

    【讨论】:

      猜你喜欢
      • 2014-01-23
      • 2013-01-03
      • 2019-07-28
      • 2020-10-21
      • 2014-07-24
      • 2022-01-11
      • 2023-03-26
      相关资源
      最近更新 更多