我是流星的新手,目前我正在测试嵌套模板。更具体地说,我试图让这个伪开关工作。
我有一个 PARENT 模板,它从 template.helper 函数获取数据,它获取 {{#each}} 的数据。
这是父模板
<template name="result">
{{#each Tresult}}
<div class="jow">
<h3>{{name}}</h3>
<p>{{type}}</p>
<div>{{> Tstatus}}</div>
</div>
{{/each}}
</template>
PARENT 还包括另一个模板 {{> Tstatus}}
这是儿童模板
<template name="Tstatus">
{{#status_is "green"}}
{{> Tstatus_green}}
{{/status_is}}
{{#status_is "red"}}
{{> Tstatus__red}}
{{/status_is}}
{{#status_is "orange"}}
{{> Tstatus__orange}}
{{/status_is}}
</template>
<template name="Tstatus_green">
<span>green</span>
</template>
<template name="Tstatus_red">
<span>red</span>
</template>
<template name="Tstatus_orange">
<span>orange {{number}}</span>
</template>
此模板还可以包含 3 个其他模板:
- Tstatus_green
- Tstatus_red
- Tstatus_orange
但问题是,我如何让这个伪开关工作。所以我只需要包含 3 个模板中的 1 个,基于它的状态颜色。
这是 PARENT 模板的辅助函数
Template.result.helpers({
Tresult:function(){
return Ttable.find()
}
})