Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Events 如何在模板中使用动态参数调用meteor助手_Events_Meteor_Helpers - Fatal编程技术网

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