简体   繁体   中英

How can I get a Session in Meteor to display in a separate window?

I'm a Meteor newbie. In my client.js file I have:

if(Meteor.isClient) {
Template.infooutput.output = function() { 
return Session.get("info"); }

I have a template:

<template name="infooutput">
{{output}} 
</template>

and then in my main page

<body>
{{>infooutput}}
</body>

Now through console, if I set the Session.set("info", "hello") I see on the screen, "hello". So that works fine however if I open another browser tab, with the same page open, I don't see the "hello". Is this update functionality only possible with use of a collection? Also, I'm a little confused about the purpose of a Session. Can you tell me why it might be used? Am I able to have current session updates shown in multiple browsers (other users viewing) without saving to my collection db? If so, how might I do it?

Session data are isolated to the current browser instance (including tabs) - so opening a new tab will give you a clean state. Session variables are designed to be a programmer-controlled means to create reactivity on an individual client. They are one of several reactive data sources which can trigger client UI updates.

Meteor is designed to sync data with the client via collections, however there are other techniques that have been developed by community members. Most notably streams .

It's also worth noting, that the server can publish documents to the client which are not necessarily represented in the database. Please see this answer for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM