【问题标题】:Thymeleaf reference using element id使用元素 id 的 Thymeleaf 参考
【发布时间】:2019-04-16 15:40:06
【问题描述】:

我的模板中有一个这样的按钮

<button id="start-button" th:text="#{start-button}">no thymeleaf</button>

我正在尝试删除 th 引用中的重复项(在我的示例中为“开始按钮”),因此文本始终来自与元素具有相同 id 的属性

有没有办法告诉 thymeleaf 从id 标签中获取属性名称#{start-button}?理想情况下,我想让 id 由我硬编码,th:text 引用它,而不是相反。我在搜索中所能找到的只是在 thymeleaf 中动态创建 id 的方法

【问题讨论】:

    标签: java templates thymeleaf


    【解决方案1】:

    不,你不能。您可以获得的最接近的是使用相同的变量来生成 id 和文本。像这样的:

    <button th:with="button='start-button'" th:id="${button}" th:text="#{${button}}" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 2016-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      相关资源
      最近更新 更多