流星从链接传递数据到模态

meteor pass data into modal from link

本文关键字:数据 模态 链接 流星      更新时间:2023-09-26

我试图将ID从一个href传递到一个模式,当链接被点击时打开。

我得到了模态弹出Ok,但不是在链接的id,我得到的是父页面的id。

我的链接代码是
 <table class="table table-striped table-condensed">
   <tbody
           <tr>
               <th>Posted</th>
               <th>ID</th>
           </tr>
           {{#each quotes}}
               <tr>
                  <td>{{submittedText}}</td>
                  <td><a href="#showQuote" class="showQuote" data-toggle="modal">{{_id}}</a></td>
               </tr>
           {{/each}}
  </tbody>

正确的引号id在表中,但是我不知道如何让这个引号id出现在打开的结果模态中。

我尝试在帮助器中捕获点击事件,如下所示

  'click #showQuote' : function(t,e) {
    console.log(this);
    console.log(t);
    console.log(e);
    debugger;
  }

但这是父ID而不是引号(这似乎只在我关闭对话框时触发)。

请问我如何传递这个?

会话变量是一种方法,但是如果你使用peppelg:bootstrap-3-modal包,你可以将父上下文传递给show函数。

javascript

Template.template_with_modal_link.events({
    'click . showQuote': function() {
         Modal.show('<ModalName>', this);    // parent context this
 } });
html

<template name="<ModalName>">
    <!-- modal format -->
</template>

如果你已经实现了显示模式的代码,你可以使用会话变量

<template name="modalstuff">
    ...
   {{#with quoteinfo}}
      MODAL HERE   
      ...
   {{/with}}
</template>
Template.modalstuff.helpers({
    quoteinfo: function() {
        return Session.get("quotedata");
    }
});

然后在你的模板中有链接

Template.template_with_modal_link.events({
    'click . showQuote': function() {
         Session.set('quotedata', this);
     }
});

this是围绕showQuote链接的数据上下文,然后将它与Session变量连接到模态