如何从HTML id中保存值以便在for循环中进行比较

时间:2015-06-11 07:52:32

标签: html meteor

我想比较for循环中的两个值,已经尝试使用#tmpid.val,而不是工作。

<template name="productpendingstatus">

       {{#each totaltemplate}}

       <table class="table table-responsive table-bordered">

        <thead><tr><td colspan="3">{{this.META.TEMPLATE_NAME}}</td>

<td id="tmpid">{{this._id}}</td> <want to compare this value in code below>

</tr></thead>
        </table>
        <div class="pendingProducts">
          <table class="table table-responsive table-bordered">

            <tbody>


                {{#each productt}}
                {{#if $eq <value of id tmpid> this.TemplateID.value }}//this is ques

                <tr>
                  <td><input type="checkbox"></td>
                  <td>{{this.ProductId.value}}</td>

                </tr> 
                {{/if}}
                {{/each}}


            </tbody>

          </table>
       </div>
       {{/each}}



    </template>

2 个答案:

答案 0 :(得分:2)

要在模板中引用父数据上下文,Spacebars现在提供the "../" notation

<template name="productpendingstatus">
       {{#each totaltemplate}}
       <table class="table table-responsive table-bordered">
        <thead><tr><td colspan="3">{{this.META.TEMPLATE_NAME}}</td>
<td id="tmpid">{{this._id}}</td> <want to compare this value in code below>
</tr></thead>
        </table>
        <div class="pendingProducts">
          <table class="table table-responsive table-bordered">
            <tbody>
                {{#each productt}}
                {{#if $eq ../_id this.TemplateID.value }}
                <tr>
                  <td><input type="checkbox"></td>
                  <td>{{this.ProductId.value}}</td>
                </tr> 
                {{/if}}
                {{/each}}
            </tbody>
          </table>
       </div>
       {{/each}}
    </template>

答案 1 :(得分:1)

您可以使用帮助程序获取父数据

<template name="productpendingstatus">
{{#each totaltemplate}}
<table class="table table-responsive table-bordered">
  <thead>
    <tr><td colspan="3">{{this.META.TEMPLATE_NAME}}</td>
    <td id="tmpid">{{this._id}}</td> 
    </tr></thead>
</table>
<div class="pendingProducts">
  <table class="table table-responsive table-bordered">
    <tbody>
      {{#each productt}}
      {{#if isPending }}
      <tr>
        <td><input type="checkbox"></td>
        <td>{{this.ProductId.value}}</td>
      </tr> 
      {{/if}}
      {{/each}}
    </tbody>
  </table>
</div>
{{/each}}

然后在js文件

 Template.productpendingstatus.helpers({
  isPending: function(){
    var parentData = Template.parentData();
    return parentData._id === this.TemplateID.value;
  }
});