0

Hi i'm junior programmer. Finally, i found a way to pass a time-leaf variable to Javascript function parameter. But I don't know how to do it when there are several String variables. How to pass multiple String variables in Javascript function? I attach the source below :)

function loadDetailView(no,type){
  ...
}

<tbody id="docsTr">
     <tr th:if="${size} == '0'">
    <td colspan=7>No data!</td>
    </tr>
     <tr th:unless="${size} == '0'" th:each="docs : ${list}" 
       **th:onclick="|loadDetailView(${docs.no},${docs.type})|"** (500 error!)

*** docs.type is String and docs.no is Integer

        <td th:text="${docs.board_no}">1</td>
        <td th:text="${docs.name}">Brian Willson</td>
        <td th:text="${docs.emp_rank}">Manager</td>
        <td th:text="${docs.reg_date}">2019-07-16</td>
      </tr>
</tbody>

error : Only variable expressions returning numbers or booleans ...

1 Answer 1

1

You can't directly put String variables in th:onclick attributes anymore. Instead, you put them in data-* attributes and reference those in your onclick functions. In your case it would look something like this (notice that it's no longer th:onclick it's just an onclick now):

<tr th:unless="${size} == '0'"
    th:each="docs : ${list}" 
    th:data-docsNo="${docs.no}"
    th:data-docsType="${docs.type}"
    onclick="loadDetailView(this.getAttribute('data-docsNo'),this.getAttribute('docsType'))"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.