Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value of click event in meteor js?

How to get the value of click event in meteor Js For example i want {{name}} this value.Here is put my code it showing *undefined*in alert box.Please verify and suggest me.

client JS:
Template.client.events({
    'click .clientrow':function(e,t){

         console.log("You Select Client Row ");
         e.preventDefault();
         alert($(e.target).closest('tr').data('_id'));

    }
});
template:
<template name="client">
<tbody>
    {{#each clientList}}
    <tr class="clientrow">
       <td data-id="{{_id}}">{{cid}}</td>
       <td>{{mrno}}</td>
       <td>{{client}}</td>
       <td>{{formatDate rdate}}</td>
       <td>{{referredby}}</td>
       <td>{{clinecian}}</td>
       <td>{{serviece}}</td>
       <td>{{episode}}</td>
       <td>{{actions}}</td>
    </tr>
     {{/each}}              
  </tbody>
</template>
like image 402
Nareshy Avatar asked Dec 01 '22 16:12

Nareshy


1 Answers

You can easily access the element that was clicked:

'click .something': function(e, t) {
  $(e.target);
}

Now, if you want the data stored in a row that was clicked, you can easily make it accessible with data HTML parameters

{{#each items}}
  <tr data-name="{{name}}" data-id="{{_id}}">...</tr>
{{/each}}

Afterwards, extract it from the row:

'click .something': function(e, t) {
  alert($(e.target).closest('tr').data('name'));
}
like image 97
Hubert OG Avatar answered Dec 10 '22 11:12

Hubert OG