我正在开发我的第一个流星应用程序,并刚刚实现了使用CollectionFS和gridfs上传图像。我可以使用<img src="{{this.url}}">
成功查看我上传的图像,但我需要从Meteor的客户端访问它。我正在尝试使用集合中其他文档的字段,并根据元数据中字段是否匹配来调用图像。 (基本上使用SpaceBars registerHelper加入这两个文档)。我很犹豫是否将其他文档与图像嵌入,因为我担心空间需求。CollectionFS从客户端获取网址
我已经试过通过Meteor-cfs-ui软件包查找,但是在翻译成我自己的空格键registerHelper时遇到了麻烦。通过Meteor-CollectionFS上的UI Helpers页面查看,我的相关信息所在的回答有一个断开的链接。
我可以查看我上传的所有图片,所以这不是使用{{this.url}}的问题。试图在客户端使用FS.Collection上的查询来获取集合中图像的url令我感到困扰。
这里是我的代码:
client.html
{{#each individualBuyOffers}}
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<h4>{{shoePict make}}</h4>
</div>
</div>
{{/each}}
client.js
UI.registerHelper('shoePict',function(context,options){
if(context){
//The goal is to query the Pictures collection
//and find the url to the picture I want
//then output it to HTML from the SafeString
//Pictures is my FS.Collection
var url = Pictures.find({'metadata.make': context});
//var collection = FS._collections[Pictures];
//return collection ? collection.findOne(id) : null;
//I know this is not the right statement
return new Spacebars.SafeString("<img src=\"{{this.url}}\">") ;
}
});
如果有任何其他更容易附着从CollectionFS图片解决方案通过html到另一个文件,我很想听到它。我只是想学习。谢谢。
哇,这是简单得多的预期,谢谢。 – Cam