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

查看:47
本文介绍了我可以订阅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天全站免登陆