我尝试创建一个基本应用,动态渲染缩略图并将动态生成的模式与每个点击相关联。我似乎无法弄清楚如何将我的mongo db中的数据插入到bootbox警报中,我知道我需要再次运行查询,但我不确定如何检索该特定条目的字段
这是html模板:
<template name="gallery">
<div class="col-xs-6 col-sm-6 col-md-2">
<a href="#" class="thumbnail" data-toggle="#">
<img src="{{img}}" alt="...">
<div class="caption">
<h5><center>{{name}}</center></h5>
</div>
</a>
</div>
</template>
这里是js。
Gallerys = new Mongo.Collection("gallerys");
if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
gallerys: function () {
return Gallerys.find({}, {sort: {createdAt :-1}});
}
});
Template.body.events({
"click a.thumbnail": function(e) {
bootbox.alert(function(){
return Gallerys.find();
};
}
});
}
答案 0 :(得分:0)
希望你最终将整个画廊移动到它自己的模板中并将辅助函数绑定到它而不是body
但是让我们处理主要问题,你的body事件处理程序需要返回数据上下文单个记录,而不是光标。点击整个图库应该会为您提供单个图库项目的上下文,其结果是this
将指向该文档,this._id
将是该文档的_id
。
Template.body.events({
"click a.thumbnail": function(e){
bootbox.alert(function(){
return Gallerys.findOne({_id: this._id});
};
}
});
我怀疑您还希望使用bootbox.dialog
而不仅仅是bootbox.alert