嵌套模板,查找父对象 [英] Nested Templates, Finding Parent

查看:64
本文介绍了嵌套模板,查找父对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列嵌套对象.像...商店和物品.

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中存储一堆data- *属性并通过Jquery搜索出我的mongdb _id项?我认为,小胡子不能让您弄清楚您来自何处并访问父范围的变量".而且这与骨干网不同,我可以在其中添加从父存储视图到子项视图的链接.

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 supports ../ in paths, which might help:

http://handlebarsjs.com/#paths

这篇关于嵌套模板,查找父对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆