QQ上的MongoDB和流星模板。我正在尝试设置一个助手,它将显示来自给定DB的每一张照片,而且我在提取图像时遇到了困难。
现在,我的DB中的一个文档如下所示:
{ "order" : 19,
"img" : "http://foo.cdninstagram.com/photo.jpg",
"time" : "99999999999",
"user" : { "username" : "ME!",
"website" : "",
"profile_picture" : "http://foo.instagram.com/foophoto.jpg",
"full_name" : "Monique Rana",
"bio" : "",
"id" : "1234567" },
"_id" : "abc123" }下面是我正在使用的代码。
<template name="currentTag">
<div class="container">
<ul class="grid effect-8" id="grid">
{{#each Tag}}
<li><img src="{{Tags.img}}"></li>
{{/each}}
</ul>
</div>
</template>我正在建造的帮手:
Template.currentTag.helpers({
Tag: function () {
return Tags.find().fetch();
}
});谢谢!
发布于 2014-08-28 05:47:16
您可以使用{{img}}而不是{{Tags.img}}来解决这个问题。{{#each Tag}}块中的数据上下文属于项本身。
另外,您不需要.fetch,因为模板可以理解游标,这些游标的效率略高,如return Tags.find();
https://stackoverflow.com/questions/25541506
复制相似问题