【问题标题】:How I can use variable as parameter in html thymeleaf如何在 html thymeleaf 中使用变量作为参数
【发布时间】:2018-12-02 16:39:34
【问题描述】:

我在我的 HTML Thymeleaf 中使用

<h1 class="timer count-title count-number" data-to="${atendida}"
data-speed="1000"></h1>

但是data-to="${atendida}" 不起作用。我的控制器:

modelAndView.addObject("atendida", size);

在这种情况下如何使用“atendida”?

【问题讨论】:

    标签: javascript html spring thymeleaf


    【解决方案1】:

    欢迎来到 SO。

    如果您只想打印对象的值,您可以这样做:

    <h1 class="timer count-title count-number" th:text="${atendida}"
    data-speed="1000">Some Timer</h1>
    

    如果你有自定义属性值,那么你可以这样做

    <h1 class="timer count-title count-number" th:attr="data-to=${atendida}"
    data-speed="1000">Timer</h1>
    

    如果您希望同时具备这两个属性,您可以这样做:

    <h1 class="timer count-title count-number" th:attr="data-to=${atendida},data-speed=${someSpeed}">Timer</h1>
    

    您可以在Thymeleaf docs under "Setting Attribute Values." 中阅读有关此内容的信息

    【讨论】:

      【解决方案2】:

      &lt;h1 class="timer count-title count-number" data-speed="1000" th:attr="data-to=${atendida}"&gt;&lt;/h1&gt;

      【讨论】:

        猜你喜欢
        • 2011-04-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-21
        • 2018-08-28
        • 2020-10-30
        相关资源
        最近更新 更多