嵌套模板,查找父项 [英] Nested Templates, Finding Parent
问题描述
我有一系列嵌套对象.说喜欢...商店和商品.
I have a series of nested objects. Say like... stores and items.
我大概有 10 家商店,每家商店都有相同的 10 件商品,同时显示在屏幕上.
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>
我遇到的主要问题是尝试使用辅助函数确定 {{qty}}.这是因为项目本身没有数量",而是取决于它与哪个商店"相关.所以我需要根据商店"+项目"找到数量.
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".
搜索这个的流星方式"是什么?是否在DOM中存储一堆数据-*属性并通过Jquery搜索我的mongdb _id项目?我不认为 mustache 允许您弄清楚您来自哪里并访问父范围的变量".它不像主干,我可以将链接从父商店视图添加到子项目视图.
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.
我不喜欢使用会话变量,因为我担心这可能会导致竞争条件(例如 Session.get('current_store_id')).
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')).
谢谢!
推荐答案
Handlebars 支持路径中的 ../
,这可能会有所帮助:
Handlebars supports ../
in paths, which might help:
http://handlebarsjs.com/#paths
这篇关于嵌套模板,查找父项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!