Nested Templates, Finding Parent

瘦欲@ 提交于 2019-12-30 10:53:50

问题


I have a series of nested objects. Say like... stores and items.

I have perhaps 10 stores, each with the same 10 items, displayed on the screen at the same time.

<template name='store'>
  {{#each items}}
   {{> item}}
  {{/each}}
</template>


<template name='item'>
  {{name}} {{qty}}
</template>

The main problem I have is trying to determine {{qty}} using a helper function. This is because the item inherently does not have a 'quantity', but rather it depends on which "store" it is related to. So I'd need to find the quantity based on the "store" + "item".

What's the "meteor way" of searching for this? Is it to store a bunch of data -* attributes in the DOM and search out my mongdb _id items via Jquery? I don't think mustache allows you to figure out where you came from and access a "parent scope's variables". And it's not like backbone where I can just add that link from the parent-store view to the child-item views.

I don't feel comfortable using session variables because I'm worried that that may cause race conditions (such as Session.get('current_store_id')).

Thanks!


回答1:


Handlebars supports ../ in paths, which might help:

http://handlebarsjs.com/#paths



来源:https://stackoverflow.com/questions/10654255/nested-templates-finding-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!