MeteorJS:用户集合如何公开新字段 [英] MeteorJS: Users collection how to expose new field

查看:116
本文介绍了MeteorJS:用户集合如何公开新字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用户集合中添加了新字段,但是当我在客户端Meteor.user()。cart(cart是我的新字段)中访问它时。它未定义。如何公开新的字段(购物车)以便它可以在客户端访问?

I have added new field in user collection but when I access it in the client side Meteor.user().cart ( cart is my new field). Its undefined. How can expose new field (cart) so that it can be access in the client?

推荐答案

最简单的方法是添加一个 null 发布商将自动发送数据而无需订阅。请务必将字段限制为仅需要的字段。

The easiest way is to add a null publisher which will automatically send the data without the need for a subscription. Be sure to limit the fields to only the ones you need.

Meteor.publish(null, function() {
  return Meteor.users.find(this.userId, {fields: {cart: 1}});
});

这篇关于MeteorJS:用户集合如何公开新字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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