简体   繁体   中英

How to pass a object parameter to the controller Spring mvc by an onclick

I have a populated table with spring mvc, I want to grab the entire object and pass via parameter to a javascript function: Sample:

  <tr th:each="prod : ${prods}">
    <td th:text="${prod.name}">Onions</td>
    <td th:text="${prod.price}">2.41</td>
    <td onclick="${prod}" >CLICK HERE</td>
  </tr>

But this not work.

I want to do this to reuse data of object on another screen.

If you are using jQuery , then there is a plugin called tabletojson which will return the equivalent json string with all the table data. That json can then be passed to any other function and manipulated easily. I think, the cleanest way.

var table = $('#mytable').tableToJSON();

Otherwise, it is required to iterate through all the columns and push it to some array

var mytable = document.getElementById("mytable");
for (var i = 0, myrow; myrow = table.rows[i]; i++) {
   //iterate through rows using "myrow"
   for (var j = 0, mycol; mycol = myrow.cells[j]; j++) {
     //iterate through all the columns using mycol

   }  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM