【发布时间】:2016-06-08 02:22:30
【问题描述】:
我的 Meteor 模板是这样排列的:
<template name="main">
{{#if youwashere}}
{{> content}}
{{#else}}
{{> introduction}}
{{/else}}
{{/if}}
</template>
为了确定用户以前是否访问过我的网站,我设置了一个本地存储,它可以工作。然后我尝试这样称呼它:
Template.main.helpers({
youwashere(){ return localStorage.getItem('herebefore'); }
});
应该发生的是:如果有一个本地存储项('herebefore'),那么它将显示名为content 的模板。但如果您的计算机上没有该项目,它会显示模板introduction。帮助程序代码最终都没有显示,所以我想知道我做错了什么。
编辑:要存储在本地存储上,我使用以下内容:
Template.introduction.events({
'click #button':function(){
localStorage.setItem('herebefore', true);}
});
【问题讨论】:
-
你在 localStorage 中存储了什么值?当
getItem返回时,它应该评估为“真实”
标签: javascript meteor meteor-blaze