Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested iteration with ability to access parent #129

Closed
snimavat opened this issue Oct 18, 2011 · 5 comments
Closed

nested iteration with ability to access parent #129

snimavat opened this issue Oct 18, 2011 · 5 comments

Comments

@snimavat
Copy link

Please see the issue here http://stackoverflow.com/questions/552934/what-javascript-templating-engine-do-you-recommend/7812081#7812081

@wycats
Copy link
Collaborator

wycats commented Nov 12, 2011

One simple approach would be to register a helper:

{{#each animals}}
  {{#each organs}}
    {{get .. this}}
  {{/each}}
{{/each}}
Handlebars.registerHelper('get', function(obj, prop) {
  return obj[prop];
});

@wycats wycats closed this as completed Nov 12, 2011
@ericsorenson
Copy link

Sorry to bring this issue back up, but I don't see how this 'get' helper will give access to the parent unless we create circular references.

Could you expand on what you mean by "{{get .. this}}"? If this is an organ, how can we use that to find the parent animal?

I would like to use handlebars.js to iterate over a list of families, and then iterate over that family's members. Inside of both loops, I want to display properties of both. However, once I get into the second iteration, none of the family variables are visible.

{{#each families}}
  {{#each members}}
    <p>{{ ( here I want a family name property ) }}</p>
    <p>{{ ( here I want a member name property ) }}</p>
  {{/each}}
{{/each}}

Is this possible with handlebars? If not, that's OK. I'd greatly appreciate any help!

@wycats
Copy link
Collaborator

wycats commented Feb 9, 2012

{{#each families}}
  {{#each members}}
    <p>{{ ../surname }}</p>
    <p>{{ name }}</p>
  {{/each}}
{{/each}}

@bjmercado
Copy link

hello guys i am learning node/express right now, the code above wont work for me i am using express-handlebars, can you help me? Is this possible with express-handlebars? here's my code. the gpareaData is iterating but the branch is not

{{#each gpareaData}}
  <tr>
    <td>
       <select class="form-control" name="gp_branch[]">
           <option value="{{id}}">{{desc}}</option>
             {{#each branch}}
           <option value="{{id}}">{{branch_desc}}</option>
             {{/each}}
       </select>		
     </td>
    <td><button type="button" class="btn btn-primary btn-sm" id="addRws3"><i class="fa fa-plus"></i></button></td>
</tr>
{{/each}}

@Farrukh-Sarmad
Copy link

{{#allData}}
all

{{#assignedData}}
assigned


{{#ifEqual id course_id }}
{{title}}

{{else}}
{{title}}

{{/ifEqual}}

{{/assignedData}}
{{/allData}}
My app control is nor even entering the inner loop . Just printing
all
all
all
Can you tell me why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants