内容简介:翻译自: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()
}
});
再次感谢 :)
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中使用?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 使用 keepalived 设置虚拟 IP 环境
- 一些 PyCharm 的使用和设置建议
- AndroidStudio基本设置,以及一些使用小技巧
- AndroidStudio基本设置,以及一些使用小技巧
- 一步步使用Docker设置Node.js
- javascript – 使用jQuery设置和获取localStorage
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Definitive Guide to Django
Adrian Holovaty、Jacob Kaplan-Moss / Apress / 2007-12-06 / CAD 45.14
Django, the Python-based equivalent to the Ruby on Rails web development framework, is presently one of the hottest topics in web development today. In The Definitive Guide to Django: Web Development ......一起来看看 《The Definitive Guide to Django》 这本书的介绍吧!
HTML 压缩/解压工具
在线压缩/解压 HTML 代码
HTML 编码/解码
HTML 编码/解码