How to pass meteor template helper as a parameter to meteor event handler? -


here's problem:

in template file:

<template name="button">      <button class="btn-class">{{disp}}</button> </template> 

in js:

template.button.events({     'click': function(event, templ) {          if (this.onclick) {              this.onclick();          }     } }) 

in other template use 'button':

<template name="buttongroup">      {{> button disp='button 1' onclick=onbutton1click}}      {{> button disp='button 2' onclick=onbutton2click}} </template> 

and js:

template.buttongroup.helpers({     onbutton1click: function() {         console.log('button 1 clicked');     },     onbutton2click: function() {         console.log('button 1 clicked');     }, }); 

obviously, can not work, because template buttongroup pass 'onbutton1click()' button, not function result(which returns 'undefined').

so how can make meteor pass helper function parameter sub template ?

return functions inside helpers instead of directly putting code want execute :

template.buttongroup.helpers({   onbutton1click: function() {     return function(event, template){       console.log('button 1 clicked');     };   },   onbutton2click: function() {     return function(event, template){       console.log('button 1 clicked');     };   } });  template.button.events({   "click": function(event, template) {     if (this.onclick) {       this.onclick(event, template);     }   } }); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -