我可以订阅 Meteor Session 以获得反应式模板渲染更新吗? [英] Can I subscribe to Meteor Session for reactive template render updates?

查看:23
本文介绍了我可以订阅 Meteor Session 以获得反应式模板渲染更新吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法订阅 Meteor Session 对象,以便在 Session 对象上设置数据时自动呈现反应式模板视图?特别是键/名称和值数据?

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 key/name and value data?

我有一个与迭代时渲染 Meteor Session 对象数据相关的类似问题.这个问题是故意不同的.我想以另一种方式获得答案,并且可能以更好的方式来做同样的事情.

I have a similar question related to rendering Meteor Session object data when iterated over. This question is specifically different on purpose. I want to get an answer out on an alternate way and possibly better way to do the same thing.

我不想调用 Session.get('name');这个用例是因为我不知道 Session 对象中的名称.

I do not want to have to call Session.get('name'); This use case is because I don't know the names in the Session object.

所以,我希望能够在车把上放一些东西

So, I would like to be able to have something in handlebars that allows me to

伪代码...

{{#each Session}}
 {{this.key}} {{this.value}}
{{/each}}

推荐答案

不确定是否订阅会话,但对于问题的第二部分,您可以使用:

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
}

然后在您的模板中:

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

不确定是否有更优雅的方法,但它有效.

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

这篇关于我可以订阅 Meteor Session 以获得反应式模板渲染更新吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆