Accessing parent context in Meteor templates and template helpers

前端 未结 9 906
别跟我提以往
别跟我提以往 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:52

    I don't know the formal way (if there is one), but to solve your issue, I would link the participants with the parent ID like this:

    {
        _id: "1234",
        question: "Whats up?",
        ...
        participants: [
          {
            _id: "abcd",
            parent_id: "1234",
            vote: 0
          }
        ]
    }
    

    and use this parent_id in helpers, events, etc. to jump back to the parent using findOne. That is obviously a sub optimal thing to do, but it's the easiest way that comes to my mind as long as there is no way of referencing the parent context. Maybe there is a way but it is very well hidden in the inner workings of Meteor without mention in the docs, if so: Please update this question if you find one.

提交回复
热议问题