javascript - Get parameter of template in Play Framework -


i have template parameter :

@(people: list[models.person]) <html> <head>       </head> <body> <table class="centered" id="table_people">  <thead>    <tr class="table_header">         <th></th>         <th class="people_column">name</th>         <th class="people_column">active</th>      </tr>  </thead>  <tbody>          @for(p <- people) {      <tr>         <td><button id="timesheet_view_" >view</button</td>         <td><b>@p.getname()</b></td>         <td>@p.isactive()</td>               </tr>               } </tbody> </table> 

that code shows list of people. , now, wanna when click on button view, shows information of people. that, have write that:

    <script>     $( "#timesheet_view_<%= people[i].id %>" )       .button()       .click(function() {          people = '<%= people[i].name %>';          showtimesheet('current', '<%= people[i].name    %>');                           })    </script> 

but can't find how value people parameter of template in javascript. try use @ character, doesn't work.

first, have fix html code: <td><button id="timesheet_view_" >view</button</td>:
close button element correctly: </button '>'.

second, have give every button unique id:

your code:

@for(p <- people) {   <tr>     <td><button id="timesheet_view_" >view</button</td>     <td><b>@p.getname()</b></td>     <td>@p.isactive()</td>             </tr>            } 

try with:

@for(p <- people) {   <tr>     <td><button id="timesheet_view_@p.id">view</button></td>     <td><b>@p.getname()</b></td>     <td>@p.isactive()</td>             </tr>            }  <script>   $(document).ready(function() {     // there better ways this, it's example     @for(p <- people) {       $("#timesheet_view_@p.id").click(function(e) {         ... // javascript code here       });     }   }); </script> 

in opinion it's better use link here (instead of button), because every button need code javascript onclick event. try link , play! work you:

@for(p <- people) {   <tr>     <td><a class="btn" href="@routes.application.view(p.id)">view</a></td>     <td><b>@p.getname()</b></td>     <td>@p.isactive()</td>             </tr>            } 

btw, if use twitter bootstrap can use class="btn" , link looks button.

start play! application , have in html source code. see code <button id="timesheet_view_@p.id">view</button> looks this:

<button id="timesheet_view_1">view</button>

<button id="timesheet_view_2">view</button>

...

<button id="timesheet_view_9">view</button>

hope helps.

best regards, gfjr


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -