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>
There is a an easier and cleaner approach. Inside the event handler this
refers to the Handlebars template context, which is actually your clientList
object. So you could do something like:
Template.client.events({
'click .clientrow':function(e,t){
console.log("You Select Client Row " + this.client);
alert(this.mrno + ' ' + this.client);
}
});
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'));
}
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.