Events 如何在模板中使用动态参数调用meteor助手
我有以下模板:Events 如何在模板中使用动态参数调用meteor助手,events,meteor,helpers,Events,Meteor,Helpers,我有以下模板: <template name="tempName" > {{#each helperOne "1" "2" }} <p>Lorem upsom</p> {{#each}} <a id="next"></a> </template> 我想在DOM上定义一个单击按钮,以动态地将参数设置为模板tempName上使用值“1”和“2”定义的helpers template.tempNam
<template name="tempName" >
{{#each helperOne "1" "2" }}
<p>Lorem upsom</p>
{{#each}}
<a id="next"></a>
</template>
我想在DOM上定义一个单击按钮,以动态地将参数设置为模板tempName上使用值“1”和“2”定义的helpers
template.tempName.events({
"click .next":function(e,tmp)
{
//how change dynamically a and b of the helperOne helper into the
// template defintion of tempName
}
});
感谢您的帮助您可以这样使用
ReactiveVar
s:
JS
HTML
hey@bouraoui{{{#each}}目前只接受数组、游标或假值。您不能将参数传递给{{#each}}块。@benstr我尝试了一下,代码运行良好,我解决了问题:)
template.tempName.events({
"click .next":function(e,tmp)
{
//how change dynamically a and b of the helperOne helper into the
// template defintion of tempName
}
});
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");
}
});
<template name="tempName" >
{{#each helperOne arg1 arg2}}
<p>Lorem ipsum</p>
{{#each}}
<a class="next"></a>
</template>
meteor add reactive-var