How to store value from HTML id for comparison in a loop

I want to compare two values ​​in a for loop, already tried using # tmpid.val, doesn't work.

<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>

      

+3


source to share


2 answers


To reference the parent data context in a template, Spacebars now provide 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>

      

+2


source


You can use a helper to get parent data

<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}}

      



and then in the js file

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

      

+1


source







All Articles