流星:设置车把变量 true/false
Meteor: Setting handlebars variable true/false
我对整个 handlebars 概念还很陌生,但基本上我希望能够在单击按钮时将变量设置为 true,然后通过在显示的模板中提交表单再次返回 false仅当变量为真时。
对于正文,我有以下代码:
<body>
{{#if notification}}
{{> notifier}}
{{else}}
{{#if currentUser}}
{{> dashboard}}
{{else}}
{{> login}}
{{/if}}
{{/if}}
</body>
假设我在仪表板中有一个 link,它在客户端 js 中运行,id 为 noticationTestLink
,我会在仪表板事件中为以下函数添加什么:
'click #noticationTestLink' : function(event) {
event.preventDefault();
}
如果我想将 notification
变量设置为 true(这是我在正文中提到的通知)。
如果我知道如何做,我很确定我可以解决剩下的问题。请原谅我在使用车把方面缺乏 experience/knowledge。我对使用 Meteor 也很陌生。提前致谢!
PS:我可能完全走错了路,但这就是我问这个问题的原因。
很难相信还没有人回答这个问题!
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>
我对整个 handlebars 概念还很陌生,但基本上我希望能够在单击按钮时将变量设置为 true,然后通过在显示的模板中提交表单再次返回 false仅当变量为真时。
对于正文,我有以下代码:
<body>
{{#if notification}}
{{> notifier}}
{{else}}
{{#if currentUser}}
{{> dashboard}}
{{else}}
{{> login}}
{{/if}}
{{/if}}
</body>
假设我在仪表板中有一个 link,它在客户端 js 中运行,id 为 noticationTestLink
,我会在仪表板事件中为以下函数添加什么:
'click #noticationTestLink' : function(event) {
event.preventDefault();
}
如果我想将 notification
变量设置为 true(这是我在正文中提到的通知)。
如果我知道如何做,我很确定我可以解决剩下的问题。请原谅我在使用车把方面缺乏 experience/knowledge。我对使用 Meteor 也很陌生。提前致谢!
PS:我可能完全走错了路,但这就是我问这个问题的原因。
很难相信还没有人回答这个问题!
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>