javascript - 基于localStorage的 meteor 激活模板

标签 javascript meteor meteor-blaze

我的 Meteor 模板是这样排列的:

<template name="main">
{{#if youwashere}}
{{> content}}
{{#else}}
{{> introduction}}
{{/else}}
{{/if}}
</template>

为了确定用户之前是否访问过我的网站,我设置了一个有效的本地存储。然后我尝试这样调用它:

Template.main.helpers({
youwashere(){ return localStorage.getItem('herebefore'); }
});

应该发生的是:如果有一个本地存储项('herebefore'),那么它将显示名为content的模板。但如果您的计算机上没有该项目,它会向您显示模板简介。帮助程序代码最终没有显示,所以我想知道我做错了什么。

编辑:要存储在本地存储上,我使用以下内容:

Template.introduction.events({
'click #button':function(){
localStorage.setItem('herebefore', true);}
});

最佳答案

您的 else 语法有点不对:

<template name="main">
{{#if youwashere}}
  {{> content}}
{{else}}
  {{> introduction}}
{{/if}}
</template>

关于javascript - 基于localStorage的 meteor 激活模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37285409/

相关文章:

javascript - 我应该如何开始学习 JavaScript、jQuery 等?我的编程知识为零

javascript - 将代码从 jquery 转换为原型(prototype)或 dojo

javascript - 在引导框对话框中使用 Blaze.render - 出现奇怪的错误

javascript - meteor : Clear a field

javascript - 将 `this.data` 的上下文转移到 Blaze/Meteor 中的其他模板?

javascript - 用于将 XML 转换为 XHTML 的 Firefox 附加组件

javascript - jQuery 点击功能未更新

meteor - 用长按/长按事件替换双击

javascript - jQuery .val ('' ) 不清除文本区域输入

mongodb - 使用 $or 进行 $text 搜索,结果为 "No query solutions"