Meteor:设置车把变量true/false

Meteor: Setting handlebars variable true/false

本文关键字:true false 变量 设置 Meteor      更新时间:2023-09-26

我对整个手柄概念还很陌生,但基本上我希望能够在点击按钮时将变量设置为true,然后通过在模板中提交表单再次返回false,只有当变量为true时才会显示。

对于身体,我有以下代码:

<body>
{{#if notification}} 
    {{> notifier}}
{{else}}
    {{#if currentUser}}
        {{> dashboard}}
    {{else}}
        {{> login}}
    {{/if}}
{{/if}}
</body>

假设我在面板中有一个链接,它在客户端js中运行,id为noticationTestLink,我会在面板事件中为以下函数放入什么:

'click #noticationTestLink' : function(event) {
   event.preventDefault();
}

如果我想将notification变量设置为true(这是我在正文中提到的通知)。

如果我知道怎么做,我很确定我能解决剩下的问题。请原谅我没有使用车把的经验/知识。我对使用流星也很陌生。提前感谢!

附言:我可能完全错了方向,但这就是我问这个问题的原因。

很难相信还没有人回答这个问题!

js:

'click #noticationTestLink' : function(event) {
   event.preventDefault();
   Session.set('notification',true);
}
Template.myTemplate.helpers({
  notification: function(){
    return Session.get('notification');
  }
});

你需要一个模板,Meteor会自动用<body>...</body>包装:

 <template name="myTemplate">
   {{#if notification}} 
     {{> notifier}}
   {{else}}
     {{#if currentUser}}
       {{> dashboard}}
     {{else}}
       {{> login}}
     {{/if}}
   {{/if}}
 </template>