meteor 模板的数据上下文
例子
每当调用模板时,都会从调用者中隐式获取模板的默认数据上下文,例如,childTemplate获得parentTemplatei.e调用者模板的数据上下文。
<template name="parentTemplate">
{{#with someHelperGettingDataForParentTemplate}}
<h1>My name is {{firstname}} {{lastname}}</h1>
//一些东西在这里
{{> childTemplate}}
{{/with}}
</template>在上述情况下,childTemplate.For示例将自动获取助手为父模板提取的所有数据,可以从childTemplate访问{{firstname}}和{{lastname}},如下所示。
<template name="childTemplate">
<h2>My name is also {{firstname}} {{lastname}}</h2>
</template>我们甚至可以通过将参数传递给模板来显式定义childTemplate的数据上下文,如以下示例所示。
<template name="parentTemplate">
{{#with someHelperGettingDataForParentTemplate}}
<h1>My name is {{firstname}} {{lastname}}</h1>
//一些东西在这里
{{> childTemplate childData=someHeplerReturningDataForChild}}
{{/with}}
</template>假设辅助对象someHelperReturningDataForChild返回类似{profession:“MeteorDeveloper”,hobby:“stackoverflowing”}之类的对象,则该特定对象将是childTemplate的显式数据上下文。现在在子模板中,我们可以做类似的事情
<template name="childTemplate">
<h2>My profession is {{profession}}</h2>
<h3>My hobby is {{hobby}}</h3>
</template>
热门推荐
1 泰迪狗狗如何训练
3 狗狗训练图
5 狗狗训练方法
6 训练狗狗不咬人
8 敏捷训练狗狗
10 训练狗狗吃饭
11 泰迪狗狗训练
12 狗狗从多大开始训练
13 狗狗训练学校费用
14 怎么去训练狗狗
15 狗狗训练狗狗
16 狗狗训练教程
17 训练狗狗装死
18 泰迪狗狗的训练方法