0
votes

I have a template (X), which shows another template (Y) several times using Collection.find(). Inside template Y, I can call functions that return stuff like Y._id and Y.data. However, I need to print Y.array[], and I do so doing

{{#each arr}}
 <button type="submit" id="confirm" value="{{userId}}">Confirm</button>
 <button type="submit" id="confirm" value="{{userId}}">Confirm</button>
{{/each}}

Outside of this code, I can access Y's data just fine, but when I'm in this each loop, this starts referring to the current array element. How can I get the _id of Y for the button click (as I need both that ID and an ID inside an array of Y for the function that the buttons call)? Or is there a better way to approach this?

1
{{../_id}} will return the ID of the parent object, which in this case would be Y._id - Brian Shamblen
This is a valid temporary solution, however it doesn't seem very Meteory as I have to embed that in the DOM then get it out with the action handler. Using this until I figure out why Template.parentData() is not working - ahota

1 Answers

3
votes

@ahota is correct for accessing the parent data context from Blaze.

From your event handler in js, use Template.parentData(1) to access the data of the immediate parent. docs