Javascript 如何使用数组在Meteor中动态渲染多个模板?
我在使用辅助对象中的数据渲染模板时遇到问题Javascript 如何使用数组在Meteor中动态渲染多个模板?,javascript,meteor,meteor-blaze,spacebars,meteor-helper,Javascript,Meteor,Meteor Blaze,Spacebars,Meteor Helper,我在使用辅助对象中的数据渲染模板时遇到问题 Template.bonus.helpers({ Userform: function(){ return UserForms.find({owner:Meteor.userId()}); }, warehouse: function(){ return Warehouse.find({}); }, DisplayForm: [ { formname: "SW - Pickin
Template.bonus.helpers({
Userform: function(){
return UserForms.find({owner:Meteor.userId()});
},
warehouse: function(){
return Warehouse.find({});
},
DisplayForm: [
{ formname: "SW - Picking" },
{ formname: "SW - Packing" },
{ formname: "SW - Putaway" }
]
});
基本上,我只想实现这样的目标:
<div id="placeholder" class="col-md-8">
{{#each DisplayForm}}
{{> {{formname}} }} //Render 3 templates "SW - Picking","SW - ....
{{/each}}
</div>
{{{#每个显示形式}
{{>{{formname}}}}//呈现3个模板“SW-Picking”,“SW-。。。。
{{/每个}}
我确信这相当容易,但我只需要正确的语法,这样我就可以使用helper中的数据作为要呈现的模板的名称。您可以使用在Meteor中动态包含模板 例如:
<body>
{{> bonus}}
</body>
<template name="bonus">
{{#each displayForm}}
{{> Template.dynamic template=formname }}
<br />
{{/each}}
</template>
<template name="picking">
Picking Template
</template>
<template name="packing">
Packing Template
</template>
<template name="putaway">
Putaway Template
</template>
这是一本书
if (Meteor.isClient) {
Template.bonus.helpers({
displayForm: [{
formname: "picking"
}, {
formname: "packing"
}, {
formname: "putaway"
}]
});
}