【问题标题】:Thymeleaf expressions百里香叶表达式
【发布时间】:2018-07-08 01:05:04
【问题描述】:

我在 Thymeleaf 页面中有这段代码,我想在其中获得类似 selectAuthorizedDriver1、selectAuthorizedDriver2、...

我试过了

<tr th:each="item: ${devices}" >
    <select th:id="selectAuthorizedDriver${item.id}" >

<tr th:each="item: ${devices}" >
    <select id="selectAuthorizedDriver${item.id}" >

还有

<tr th:each="item: ${devices}" >
    <select th:id="selectAuthorizedDriver${id}(id=${item.id})" >

但要么我得到了错误:

 Could not parse as expression: "selectAuthorizedDriver${item.id}" 

或字面意义上的"selectAuthorizedDriver${item.id}"

【问题讨论】:

    标签: javascript jquery html spring-boot thymeleaf


    【解决方案1】:

    对于只需要字符串的表达式,您可以将它们附加在一起。在你的例子中:

    <tr th:each="item: ${devices}" >
        <select th:id="${'selectAuthorizedDriver' + item.id}">
    

    您也可以使用preprocessing 完成此操作,但在这种情况下不需要。 (如果你需要写一个 th:field 表达式,你必须这样做)。

    <tr th:each="item: ${devices}" >
        <select th:id="${'selectAuthorizedDriver__${item.id}__'}">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-14
      • 2015-11-29
      • 1970-01-01
      • 2015-12-09
      • 2017-04-05
      • 2017-06-29
      • 2021-12-11
      相关资源
      最近更新 更多