Meteor:设置车把变量true/false
Meteor: Setting handlebars variable true/false
我对整个手柄概念还很陌生,但基本上我希望能够在点击按钮时将变量设置为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>
相关文章:
- JavaScript-切换“;全部检查”;复选框true/false
- true==false以某种方式计算为true
- Javascript似乎在说true ==false
- JavaScript onkeydown, return true,false
- 从异步函数返回true/false以用于同步if()
- 函数返回undefined而不是true/false
- 为什么true/true是1,true/false是无穷大,false/true是0,false/false是NaN
- 检查对象数组是否包含布尔值true/false
- 函数:根据字符串中是否存在子字符串返回 True/False
- 如何将 ng-show 与控制器中返回 true/false 的函数一起使用
- 在input.checked=true/false _without_ jQuery上触发一个事件
- jQuery javascript未正确返回true/false
- 如何从嵌套的jquery回调函数中返回true/false
- 如何在骨干模型属性中设置布尔值true/false
- 如何使用angular或javascript在基于true/false返回的html中显示值
- 基于true/false变量显示/隐藏进度条
- Node.js在返回true/false时停止函数
- 是否可以将true/false值传递给ajax函数
- 根据Webix中的复选框值编辑true/false
- Meteor:设置车把变量true/false