在meteor中显示来自两个不同集合的元素
我有两个不同的meteor集合,一个是用于存储图像的文件集合:在meteor中显示来自两个不同集合的元素,meteor,meteor-autoform,Meteor,Meteor Autoform,我有两个不同的meteor集合,一个是用于存储图像的文件集合: Images = new FS.Collection("images", { stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})] }); 另一个是用于存储这些图像信息的集合: Photos = new Mongo.Collection("photos"); Photos.attachSchema(new SimpleSchema({ userI
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})]
});
另一个是用于存储这些图像信息的集合:
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.findOne({_id: this.userId}).username},
},
groupMembers: {
type: String
},
comments: {
type: String,
autoform:{
rows: 5
}
},
fileId: {
type: String
}
}));
我构建了这个助手函数来帮助在模板上显示数据:
Template.imagesSubmitted.helpers({
photos: Photos.find(),
image: function(){Images.findOne({_id: Template.instance().data.image}).url();
}
});
Images.allow({
download: function () {
return true;
},
fetch: null
});
下面是显示图像和照片信息的HTML代码:
</template>
<template name = "imagesSubmitted">
List of photos
{{#each photos}}
<div class = "uploadedImage">
This is an image
{{> photo}}
<img src="{{this.image}}" class = "tableImage" alt="thumbnail">
</div>
{{/each}}
</template>
照片列表
{{{每张照片}
这是一个图像
{{>照片}
{{/每个}}
不幸的是,该页面没有显示来自这两个数据库的任何内容。图像仅显示为备用“缩略图”,并且{{{>photo}
似乎不显示来自照片集合的任何信息
有办法解决这个问题吗?还有没有一种方法可以简化这个过程,这样我只使用一个集合,并且仍然能够使用cfs:autoform来创建和发布收集图像的表单 您是否尝试在浏览器控制台中使用该查询?像照片一样。find().fetch();
您正在定义照片模板吗?请确保允许下载功能
发件人:
是的,看起来对象就在那里:Photos.find().fetch()[Object,Object,Object,Object,Object],那么照片模板呢。。。你定义了它吗?没有,但是当我删除它时,我仍然看不到元素应该显示的图像。这里是我拥有的:images.allow({download:function(){return true;},fetch:null});我添加了你建议的参数,结果没有什么不同。检查您是否已发布和订阅它们,并检查路径。我现在注意到的是:1)您正在为集合中的每个照片文档呈现一个
{{>photo}
模板(该模板不存在?)。如果模板不存在,则此操作无法工作。2) 我相信,
拥有照片
收藏中的照片文档的范围。所以它希望Photos
collection有image
field。。?
Images.allow({
download: function(userId, fileObj) {
return true
}
})