Meteor 使用meteror autoform记录用户名
我正在使用cfs:autoform创建一个表单,以从客户端提交的内容中捕获照片和标题,如下所示:Meteor 使用meteror autoform记录用户名,meteor,meteor-autoform,Meteor,Meteor Autoform,我正在使用cfs:autoform创建一个表单,以从客户端提交的内容中捕获照片和标题,如下所示: Photos = new Mongo.Collection("photos"); Photos.attachSchema(new SimpleSchema({ userId:{ type: String, autoValue:function(){return this.userId}, }, userName:{ type: String, a
Photos = new Mongo.Collection("photos");
Photos.attachSchema(new SimpleSchema({
userId:{
type: String,
autoValue:function(){return this.userId},
},
userName:{
type: String,
autoValue:function(){return Meteor.users.find({_id: this.userId}).username},
},
groupMembers: {
type: String
},
comments: {
type: String
},
fileId: {
type: String
}
}));
我已经获得了成功捕获和填写用户ID的代码,以及评论和上传的照片,但我似乎无法获得捕获用户名的代码 这很可能是因为您使用的是
find
而不是findOne
。由于find
返回一个游标而不是单个文档,因此无法访问用户名
值,因为它不是游标的属性。如果您将其更改为findOne
,它应该可以工作
userName:{
type: String,
autoValue:function(){return Meteor.users.findOne({_id: this.userId}).username},
}
{u id:this.userId}).username}
和username
不应该像上面的userId
那样匹配吗?一个不是照片模式中的名称(因此可以是任何名称),另一个不是用户集合中的用户名?