Can I subscribe to Meteor Session for reactive template render updates?

前端 未结 4 1562
余生分开走
余生分开走 2021-01-07 11:43

Is there a way to subscribe to the Meteor Session object so that a reactive template view automatically renders when data is .set on the Session object? Specifically the ke

4条回答
  •  终归单人心
    2021-01-07 12:42

    Unsure about subscribing to the session, but for the second part of your question, you can use this:

    Template.hello.session = function () {
      map = []
      for (prop in Session.keys) {
        map.push({key: prop, value: Session.get(prop)})
      }
      return map
    }
    

    then in your template:

    {{#each session}}
      {{key}} {{value}}
    {{/each}}
    

    Not sure if there's a more elegant way but it works.

提交回复
热议问题