我的Meteor模板安排如下:
<template name="main"> {{#if youwashere}} {{> content}} {{#else}} {{> introduction}} {{/else}} {{/if}} </template>为了确定用户之前是否访问过我的网站,我设置了一个可以运行的本地存储。 然后我尝试这样称呼它:
Template.main.helpers({ youwashere(){ return localStorage.getItem('herebefore'); } });应该发生的是:如果有一个localstorage项('herebefore')那么它将显示名为content的模板。 但是,如果您的计算机上没有该项目,它将显示模板introduction 。 帮助代码最终都没有显示出来,所以我想知道我做错了什么。
编辑:要存储在本地存储,我使用以下内容:
Template.introduction.events({ 'click #button':function(){ localStorage.setItem('herebefore', true);} });My Meteor template is arranged like this:
<template name="main"> {{#if youwashere}} {{> content}} {{#else}} {{> introduction}} {{/else}} {{/if}} </template>To determine whether a user has been to my site before, I've setup a local storage, which works. I have then tried calling it like this:
Template.main.helpers({ youwashere(){ return localStorage.getItem('herebefore'); } });What is supposed to happen, is this: if there is a localstorage item ('herebefore') then it would show the template named content. But if you did not have that item on your computer, it would show you the template introduction. The helper code ends up showing neither, so I am wondering what I am doing wrong.
EDIT: To store on local storage, I use the following:
Template.introduction.events({ 'click #button':function(){ localStorage.setItem('herebefore', true);} });最满意答案
你的else语法只是有点偏离:
<template name="main"> {{#if youwashere}} {{> content}} {{else}} {{> introduction}} {{/if}} </template>Your syntax for else was simply a bit off:
<template name="main"> {{#if youwashere}} {{> content}} {{else}} {{> introduction}} {{/if}} </template>更多推荐
发布评论