基于localStorage的流星激活模板(Meteor activating template based on localStorage)

编程入门 行业动态 更新时间:2024-10-26 20:32:00
基于localStorage的流星激活模板(Meteor activating template based on localStorage)

我的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>

更多推荐

本文发布于:2023-08-07 20:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465929.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流星   模板   localStorage   Meteor   based

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!