Reputation: 931
So here's the scenario, I need to pass an id of the parent with the action helper within a nested each loop.
{{#each}} {{! iterating the model here (arrayController) }}
{{#if showingApplicants}} {{! this is set by a button that changes a property inside this particular model object}}
{{#each applicants}}
<button {{action addLabel _id}}>Add Label...</button>
{{/each}}
{{/if}}
{{/each}}
I have tried doing ../_id
and ../../_id
. Both of which represent an undefined value. Any clues? ALSO: Is it possible to pass two values in the action helper?
Upvotes: 1
Views: 822
Reputation: 1948
You can create variables on your #each
blocks so you can refer to them on any context
{{#each x in content}}
{{#if x.showingApplicants}}
{{#each applicant in x.applicants}}
<button {{action addLabel x.id}}>Add Label...</button>
{{this.controllerProperty}}
{{x.parentModelProperty}}
{{y.childModelProperty}}
{{/each}}
{{/if}}
{{/each}}
You could also not name applicant, but if you start by naming the outer context, I would suggest doing it for the nested each
as well for consistency and to avoid possible name clashes (between the outer variable and child properties).
Hope this helps
Upvotes: 2
Reputation: 931
The workaround for this issue was to map out the model data to have an id object that contained the parent id and the child id.
Upvotes: -1