如何在CollectionFS中将图像从自动表单链接到用户集合以显示个人资料图片
How to link image from autoform to user collection in CollectionFS for displaying a profile picture?
使用autoform保存用户上传到"images"集合中的个人资料图片。然而,我不知道如何调用特定的图片被加载到模板上。以下命令不显示模板上的图像。但是,如果我将Images.find({'doc.metadata.ownerId':Meteor.userId()});
更改为Images.find()
,则会加载所有图像,但我不能指定我想要的是哪一个。
this.Images = new FS.Collection("Images", {
stores: [new FS.Store.GridFS("Images", {})]
});
Images.files.before.insert(function(doc) {
doc.metadata = {
date: Date.now(),
ownerId: this.userId
};
console.log("before", doc);
return doc;
});
Template.photos.helpers({
Images: function () {
Images.find({'doc.metadata.ownerId':Meteor.userId()});
}
});
您正在做的是用户上传的图像,您正在添加userid作为元值并存储它。它只允许你获取用户上传的所有图片。由于您还使用了时间戳,所以最新的一个将是最新的个人资料图片。
或者在用户文档中,在"profile
"后面增加"photo
"字段。
这样,当用户上传照片时,将photo
值设置为所上传图像的键,并且为了显示照片,您可以执行
Images.findOne({ _id: Meteor.user().profile.photo })
如果您使用autoform,在profile.photo
中存储图像ID将会容易得多。
这个怎么样:
Template.photos.helpers({
Images: function () {
Images.find({'metadata.ownerId':Meteor.userId()});
}
});
相关文章:
- 将当前用户的 ID 推送到 meteorjs 中集合/文档的内部数组
- 如何组织用户系统的Mongo集合
- MeteorJS:用户集合如何公开新字段
- Accounts.onCreateUser 未将字段添加到 Meteor 的用户集合中
- 根据用户配置文件中的数组在集合中查找
- 骨干 - 当用户通过特定帖子访问网站时,如何管理集合初始化
- 如何动态创建集合名称(取决于用户信息)
- 流星:如何获取用户帐户包以将新的用户文档写入远程集合
- Meteor:使用ReactiveVar创建一个加载小部件,用于订阅用户集合
- Meteor仅为指定用户(管理员)发布所有集合
- 在流星中向用户集合添加字段的正确方式
- Stamplay JS SDK-根据当前用户返回集合中的项目
- metro.js-将数组推送给用户集合
- Meteor获取模式集合中的用户数据2,并自动形成
- 将用户发布到其他集合时出现问题
- 基于当前用户属性发布流星集合
- Meteor 1.4,如何访问包中用户定义的集合
- 如何更新嵌套的用户集合
- Angular-meteor用户集合只返回1个对象
- 将用户添加到现有Mongodb集合中的数组中