javascript – 如何设置Meteor.userId()以在autoform / simple-schema中使用?

栏目: Node.js · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/25369368/how-do-you-set-the-meteor-userid-for-use-within-autoform-simple-schema

假设我想在用户登录后显示用户购物项目的列表.我正在使用autoform和simple-schema来生成表单元素.当用户第一次登录时,将显示空白购物清单表单.提交表单时,购物清单会保存在数据库中.

我想知道的是如何为每个用户保存这些数据.

通常我会做这样的事情:

ShoppingList.insert({
        name: item_name,
        price: 0,
        createdBy: Meteor.userId()
      });

我将如何使用autoform和simple-schema实现这一目标?是否有可能做这样的事情:

Schema.ShoppingList = new SimpleSchema({
item: {
    type: String,
    regEx: /^[a-zA-Z-]{2,25}$/
},
price: {
    type: Number,
    regEx: /^[0-9]{2,25}$/
},
createdBy: {
    type: String,
    value: Meteor.userId()
}
});

再次感谢 :)

如果您还使用Collection2,则使用autoValue:
Schema.ShoppingList = new SimpleSchema({
item: {
    type: String,
    regEx: /^[a-zA-Z-]{2,25}$/
},
price: {
    type: Number,
    regEx: /^[0-9]{2,25}$/
},
createdBy: {
    type: String,
    autoValue:function(){ return this.userId }
}
});

翻译自:https://stackoverflow.com/questions/25369368/how-do-you-set-the-meteor-userid-for-use-within-autoform-simple-schema


以上所述就是小编给大家介绍的《javascript – 如何设置Meteor.userId()以在autoform / simple-schema中使用?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

面向模式的软件体系结构(卷1) (平装)

面向模式的软件体系结构(卷1) (平装)

Frank Buschmann、Regine meunier、Hans Rohnert、Peter Sommerlad、Michael Stal / 贲可荣、郭福亮 / 机械工业出版社 / 2003-1 / 45.0

一起来看看 《面向模式的软件体系结构(卷1) (平装)》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试