javascript - js event in a handlebars template -


when click on button, template have table feeded.

i want action when double click row of table in handlebar template.

<body> <script id="lodgersearchresult-template" type="text/x-handlebars-template">     <div class="span12">     <table id="lodgersearchresulttable" data-show-header="true" class="table" data-toggle="table" data-height="250">     <thead>     <tr>     <th>#</th>     <th>nom</th>     <th>date de naissance</th>     <th>n.a.s.</th>     <th>n.a.m.</th>     <th>immeuble</th>     </tr>     </thead>     <tbody>        {{#each this}}        <tr>          ...          ...        </tr>        {{/each}}     </tbody>   </table> </script> </body>    <script>    $('#lodgersearchresulttable > tbody').dblclick(function () {     alert($(this).text());    }); </script> 

actually, nothing happen.

edit: put double click event in ajax success answer

$('#lodgersearch').on('click', function (e) {      var searchparam = $('#srch-term').val();     var url = "http://localhost:8080/lodgers/search";     if (searchparam != "") {         url = "http://localhost:8080/lodgers/search?searchtemp=" + searchparam;     }      jquery.ajax({         type: "get",         url: url,         success: function (data, status, jqxhr) {              $("#lodgersearchresult").empty().append(template(data));             // line added             $('#lodgersearchresulttable > tbody').dblclick(function () {                 alert($(this).text());             });          },         error: function (jqxhr, status) {             // error handler             alert("error " + jqxhr + " -  " + status);         }     });     // e.preventdefault(); }); 

is there cleaner way same thing?

i mean:

<script>   alert('table before: ' + string($('#lodgersearchresulttable')));   $( document ).ready(function() {      alert('table after: ' + string($('#lodgersearchresulttable')));      $('#lodgersearchresulttable > tbody').dblclick(function () {         alert($(this).text());      });   }); </script> 

other non-clear solution

<script>    $( document ).ready(function() {       $('#lodgersearchresult').dblclick(function (event) {          console.log(event.target);          var res_table = $('#lodgersearchresulttable > tbody');         if( res_table ) {             alert(res_table.text());         }      });   }); </script> 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -