meteor – 模板助手参数(空格键)

我需要一些关于如何解决我的问题的想法。 我有一个表格下面的HTML模板。 它显示了5行,并在每行的末尾(在最后的TD)有一个button,触发引导模式(popup窗口)。 我正在使用spacebars {{#each}}遍历所有的游标,但问题是与模式。 它只显示第一行的数据,每行logging相同的数据。 这是因为模式的ID对于每个logging都是相同的(它是第一个, #subsPopup )。 我需要以某种方式为每行传递不同的ID,如#subsPopup{{var}} 。 任何想法我怎么能做到这一点?

 <!-- subscribers table --> <table class="table table-hover"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> <th>Created</th> <th>Modified</th> <th>Mailing lists</th> </tr> </thead> <tbody> {{#each subsList}} <tr> <td>{{firstName}}</td> <td>{{lastName}}</td> <td>{{email}}</td> <td>{{createdDate}}</td> <td>{{modifiedDate}}</td> <!-- Trigger the modal (popup window) with a button --> <td> <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#subsPopup">Show</button> <!-- Modal --> <div id="subsPopup" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Mailing List for <b>{{firstName}} {{lastName}}</b> ({{email}})</h4> </div> <div class="modal-body"> <p>{{mailLists}}</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </td> </tr> {{/each}} </tbody> </table> 

您的订阅集合可能具有_id字段,因此您可以尝试输出{{_id}}

万一有人遇到这个问题…

我解决这个问题的方法…(不知道这是否是最优雅的,但它确实对我有用)

这里是一个例子:

[meteor模板文件 – “coolmodal.html” – 包含引导模态组件]

 <template name="mymodal"> <!-- This button we can use to trigger the modal to display--> <button class="btn btn-success btn-lg" type="button"> <div class="modal fade" id="mycoolmodal" tabindex="-1" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title">{{modalDetails}}</h4> </div> <div class="modal-body"> <p>Cool stuff I like to write here</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal --> </template> 

[Meteor Client JS文件 – “cool.js” – 包含模板助手等]

 Template.mymodal.events({ 'click .img-thumbnail'(event, instance) { event.preventDefault(); // Stops the page from attempting a reload. Session.set('myInfoForModal', this.my_data_you_want); $('#coolmodal').modal('show'); } }); Template.registerHelper('modalDetails',function(input){ return Session.get("myInfoForModal"); });