i have the following template :
<template name="tempName" >
{{#each helperOne "1" "2" }}
<p>Lorem upsom</p>
{{#each}}
<a id="next"></a>
</template>
the helper :
template.tempName.helpers({
"helperOne":function(a,b)
{
console.log("a = "+a+" b ="+b);
}
});
i want to define a click on a DOM to set dynamically the params to helpers defined with the values "1" and "2" on the template tempName
template.tempName.events({
"click .next":function(e,tmp)
{
//how change dynamically a and b of the helperOne helper into the
// template defintion of tempName
}
});
thank you for help
You could use ReactiveVars like this :
JS
Template.tempName.onCreated(function(){
this.arg1 = new ReactiveVar("1");
this.arg2 = new ReactiveVar("2");
});
Template.tempName.helpers({
helperOne: function(arg1, arg2){
console.log("helperOne called with", arg1, arg2);
},
arg1: function(){
return Template.instance().arg1.get();
},
arg2: function(){
return Template.instance().arg2.get();
}
});
Template.tempName.events({
"click .next": function(event, template){
template.arg1.set("whatever");
template.arg2.set("you want");
}
});
HTML
<template name="tempName" >
{{#each helperOne arg1 arg2}}
<p>Lorem ipsum</p>
{{#each}}
<a class="next"></a>
</template>
Don't forget to add the package to your Meteor app.
meteor add reactive-var
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