1
{{#if docs}}
    {{#each docs}}
        <h4>customer number : {{this.customer}}</h4>
        <h4>number of liters required : {{this.volume}}</h4>
        {{#if alldri}}
            {{#each alldri}}
                <h5>{{this.name}}</h5>
            {{/each}}
        {{/if}}
    {{/each}}
{{/if}}

both docs and alldri are the JSON arrays.All the objects under docs array are printing well but the not able to see objects under alldri array.

alldri array is

[ { _id: 5c94c61f955fa804fc96657c,
    name: '1',
    phonenumber: '9640121413',
    email: 'taditarun123@gmail.com'
    __v: 0 },
  { _id: 5c94c683955fa804fc96657d,
    name: '2',
    phonenumber: '9493447471',
    email: 't@gmail.com'
    __v: 0 } ]

docs array is

[ { _id: 5c93a9812671d127785c105e,
customer: '1',
merchant: '11',
volume: '12',
__v: 0 } ]
Tarun
  • 29
  • 7

1 Answers1

0

Your problem is actually not with the if directives. It's with scope. You lose access to the parent scope when you're inside an each directive. So you are not able to access alldri inside. That's why it's evaluating to false and not rendering that content.

See Access properties of the parent with a Handlebars 'each' loop.

Your code will work if your template is changed to:

{{#if docs}}
    {{#each docs}}
        <h4>customer number : {{this.customer}}</h4>
        <h4>number of liters required : {{this.volume}}</h4>
        {{#if ../alldri}}
            {{#each ../alldri}}
                <h5>{{this.name}}</h5>
            {{/each}}
        {{/if}}
    {{/each}}
{{/if}}

Note the ../alldri.

https://jsfiddle.net/nowgy52m/7/

Matt Welke
  • 1,441
  • 1
  • 15
  • 40