Get object from thymeleaf to js

I have a for:each like this:

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

The question is how can i get the entire ${bill} to a variable in js or jquery because i need more information, i saw the documentation and it said:

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

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

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

but i have tried this on a external js file and does not work , so i need 1 solution for this.

imagen del error

Upvotes: 0

Views: 4664

Answers (1)

You can have ${bills} as a javascript object, try this

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

Upvotes: 3

Related Questions