Accessing parent context in Meteor templates and template helpers

前端 未结 9 912
别跟我提以往
别跟我提以往 2020-12-09 01:10

I\'m running into a template context situation that I\'m having a hard time finding a way around.


Here\'s the template in question:



        
9条回答
  •  无人及你
    2020-12-09 01:46

    I was stuck in a similar way and found that the Template.parentData() approach suggested in other answers currently doesn't work within event handlers (see https://github.com/meteor/meteor/issues/5491). User Lirbank posted this simple workaround:

    Pass the data from the outer context to an html element in the inner context, in the same template:

    {{#each companies}}
      {{#each employees}}
        Do something
      {{/each}}
    {{/each}}
    

    Now the company ID can be accessed from the event handler with something like

    $(event.currentTarget).attr('companyId')
    

提交回复
热议问题