Javascript 获取对象thymelaf

Javascript 获取对象thymelaf,javascript,spring,spring-boot,thymeleaf,Javascript,Spring,Spring Boot,Thymeleaf,我有一个用于:每个如下: <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>

我有一个
用于:每个
如下:

<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>

我已经在一个外部JavaScript文件上尝试过了,但它不起作用。

如果您使用的是Thymeleaf 3,这就足够了

<script th:inline="javascript">
    var user  name = [[${bill}]];
</script>

var用户名=[[${bill}]];

您必须将它放入
.html
文件中,因为默认情况下它处理
.html
文件。您可以将它添加到
.html
文件中,并且它将在
.html
文件中上述代码之后包含的脚本中可用。如果您使用的是Thymeleaf 3,这就足够了

<script th:inline="javascript">
    var user  name = [[${bill}]];
</script>

var用户名=[[${bill}]];
您必须将它放入
.html
文件中,因为默认情况下它处理
.html
文件。您可以将其添加到
.html
文件中,它将在
.html
文件中上述代码之后包含的脚本中可用。您可以在html中使用“数据”属性:

<td th-data:id="${bill.id}" th-data:name="${bill.nome}" class="js-datas">
xmlns:data="http://www.thymeleaf.org/extras/data"
您必须在HTML中使用以下命名空间:

<td th-data:id="${bill.id}" th-data:name="${bill.nome}" class="js-datas">
xmlns:data="http://www.thymeleaf.org/extras/data"
您可以在HTML中使用“数据”属性:

<td th-data:id="${bill.id}" th-data:name="${bill.nome}" class="js-datas">
xmlns:data="http://www.thymeleaf.org/extras/data"
您必须在HTML中使用以下命名空间:

<td th-data:id="${bill.id}" th-data:name="${bill.nome}" class="js-datas">
xmlns:data="http://www.thymeleaf.org/extras/data"