【发布时间】:2015-05-11 12:30:44
【问题描述】:
我有两个不同的流星集合,一个是用于存储图像的文件集合:
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 创建和发布收集图像的表单?
【问题讨论】: