Meteor - Conditionally return a group of event Handlers -


in meteor best way conditionally add set of event handlers?

for example i'm trying code below (this code not work, idea of i'm trying achieve.)

template.page_article.events( function(){   if (something){     return {       some_event_name1,       some_event_name2,     }   } else {     return {       some_event_name3,       some_event_name4,     }   } }) 

what best way this? tried set variable outside events() not solution because variable gets shared amongst other templates.

what you're trying achieve sounds bad solution me, here's way it:

template.page_article.events((function(){   if (something){     return {       '<event>': function(){ console.log("a1") },       '<event>': function(){ console.log("a2") }     }   } else {     return {       '<event>': function(){ console.log("b1") },       '<event>': function(){ console.log("b2") }     }   } })()) 

edit

and added comment, sounds bad solution. instead:

template.page_article.events({     '<event>': function(event, template){         if(something){             console.log("do a1")         }else{             console.log("do b1")         }     }     '<event>': function(event, template){         if(something){             console.log("do a2")         }else{             console.log("do b2")         }     } }) 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -