Access context variable from different scope in each loop handlebars

170 views Asked by At

I'm quite new to handlebars, and I'm wondering if I can access other objects field values inside an each loop created using another object. This is what I'm currently trying to do, I get no value on the table cell that I'm trying to set {{../entry/UnitPrice}} on the value.

JavaScript code:

context = {
        prod : prodResult.records,
        entry : entryResult.records,
        ts : prodResult.totalSize
      }
      res.render('prodlist', context)

Handlebars code:

<h1>DONE</h1>
<table>
    <tr>
        <th></th>
        <th>Name</th>
        <th>Unit Price</th>
    </tr>
    {{#each prod}}
    <tr>
        <td><input type="checkbox" value="{{Id}}"></td>
        <td>{{Name}}</td>
        <td>{{../entry.UnitPrice}}</td>
    </tr>
    {{/each}}
</table>

Thanks in advance.

0

There are 0 answers