【问题标题】:Thymeleaf (th:each + th:selected) : accessing variable in selected attribute from each loopThymeleaf (th:each + th:selected) :从每个循环访问选定属性中的变量
【发布时间】:2019-05-07 02:13:17
【问题描述】:

如果某个列表包含来自每个循环的值,我想选择选项标记。但是从选定属性的循环中访问变量存在一些问题。 这是我的代码:

<option th:each="facility: ${facilities}" th:value="${facility.id}" th:text="${facility.name}" th:selected="${apartment.facilities.contains(facility.id)}"></option>

下一个代码也不起作用:th:selected="${#lists.contains(apartment.facilities, facility.id)}"

它适用于 th:selected="${apartment.facilities.contains(SOME_DIGIT)}"th:selected="${facility.id == SOME_DIGIT}"。怎么了?

【问题讨论】:

  • 为此,您需要在 for-each 循环中实现 th:if 条件。
  • 我需要从循环中获取所有值,并且应该选择其中一些。
  • 我猜facility.idapartment.facilities 是不同的类型?一个是int,一个是string?

标签: java spring thymeleaf server-side template-engine


【解决方案1】:

解决方案:有不同的类型。 List 包含 int 值,但我检查过 contains 的值类型很长。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-24
    • 2014-03-07
    • 2019-02-07
    • 2019-08-05
    • 2012-11-18
    • 1970-01-01
    • 2021-03-15
    相关资源
    最近更新 更多