I have some code similar to the following:
In myapp.html
<template name="problems">
<div class="problems">
{{#each problems}}
{{> problem}}
{{/each}}
</div>
</template
<template name="problem">
<div class="problem">
<div class="problem-text" id={{_id}}>{{text}}</div>
</div>
</template>
In myapp.js
Template.problem.events = {
'click .problem-text' : function () {
var user_id = Session.get('user_id');
// how to get problem_id of clicked item?
Router.gotoProblem(user_id, problem_id);
}
};
In this situation I want to get the id of the that matched .problem-text and was clicked.
I would like to know the "object" that generated the event? How do I do this?
The selected answer for this question will ONLY get the _id
, and that too if _id
is used in templates.
So better use, event.target
, that will give COMPLETE object. So that can be used with jQuery or MooTools.
Template.top_nav.events({
'mousedown, .nav li a': function(evt){
console.log('the class of object that was clicked is ' + $(evt.target).attr("class"));
}
})
Try this:
Template.problem.events = {
'click .problem-text' : function () {
var user_id = Session.get('user_id');
// how to get problem_id of clicked item?
Router.gotoProblem(user_id, this._id);
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With