简体   繁体   English

如何在流星中将数据设置为模板

[英]How to set data to a template in meteor

I'm new to meteor i want to set data to a template 我是流星的新手,我想将数据设置为模板

In Javascript: 用Javascript:

Template.test.helpers({
  configDoc:function(){
    return Session.get('configDoc');
  }, 
});

In html: 在html中:

<template name="test">
  {{#each doc in configDoc}}
    {{> details doc }}
  {{/each}}
</template>

I want to set the data on the details template (not shown here) to doc using {{> details doc }} but this is not working for me :-( 我想使用{{> details doc }}details模板(此处未显示)上的数据设置为doc但这对我不起作用:-(

Please let me know where I'm going wrong. 请让我知道我要去哪里了。

See the docs here. 请参阅此处的文档。

Change Template.test to this: 将Template.test更改为:

<template name="test">
  {{#each configDoc}}
    {{> details}}
  {{/each}}
</template>

in Template.details , you can directly display any attributes in the template with {{attrA}} . Template.details ,您可以使用{{attrA}}直接显示模板中的任何属性。

Or if you create helper functions the current doc can be accessed as the this object. 或者,如果您创建辅助函数,则可以将当前文档作为this对象进行访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM