【问题标题】:Get object from thymeleaf to js从thymeleaf获取对象到js
【发布时间】:2018-04-25 01:24:27
【问题描述】:

我有一个这样的for:each

<tbody>
    <tr th:each="bill : ${bills}" id="bill">
        <td th:text="${bill.bill_id}"></td>
        <td th:text="${bill.client.phone}"></td>
        <td th:text="${bill.date}"></td>
        <td><a href="#" class="btn btn-info btn-xs" data-toggle="modal" id="open-modal">Ver detalles</a></td>
    </tr>
</tbody>

问题是我如何将整个 ${bill} 获取到 js 或 jquery 中的变量,因为我需要更多信息,我看到了文档并说:

<script th:inline="javascript">
/*<![CDATA[*/
    ...

    var user  name = /*[[${bill}]]*/ '';

    ...
/*]]>*/
</script>

但是我已经在外部 js 文件上尝试过这个并且不起作用,所以我需要 1 个解决方案。

imagen del error

【问题讨论】:

    标签: javascript spring spring-boot thymeleaf


    【解决方案1】:

    您可以将${bills} 作为 javascript 对象,试试这个

    <script th:inline="javascript">
    /*<![CDATA[*/
    
        var bills = [[${bills}]];  //Make sure this is bills and not bill as you have done it.
        console.log(bills);
    
    /*]]>*/
    </script>
    

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 2021-08-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 1970-01-01
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多