【问题标题】:Dynamic bootbox modals in meteor流星中的动态引导箱模态
【发布时间】:2015-04-21 03:57:03
【问题描述】:

我正在尝试创建一个基本应用程序,该应用程序可以动态呈现缩略图并将动态生成的模式关联到每个点击。我似乎无法弄清楚如何将我的 mongo db 中的数据插入到引导箱警报中,我知道我需要再次运行查询,但我不确定如何检索该特定条目的字段。

这是 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();
      };
    }
  });
}

【问题讨论】:

    标签: javascript mongodb meteor bootbox


    【解决方案1】:

    希望您最终将整个图库移动到它自己的模板中,并将辅助函数绑定到该模板而不是 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-26
      • 2013-11-26
      • 2018-03-03
      • 1970-01-01
      相关资源
      最近更新 更多