我如何在Meteor中执行此操作?
Template.foo.bar = function() {
someVar = return value of some other function
return SomeCollection and someVar;
}
------- ----模板
{{#each someCollection}}
{{someVar}} {{someCollectionField}}
{{/each}}
在普通的javascript中我可以使用一个数组来返回多个值,它在Meteor中是如何工作的?
答案 0 :(得分:3)
你可以返回一个js对象并使用把手来完成它
客户js
Template.foo.bar = function() {
someVar = getmyotherfunction();
return {
SomeCollection: SomeCollection.find({...}),
someVar: someVar
};
}
客户端HTML
<template name="foo">
{{#each bar.SomeCollection}}
{{bar.someVar}}
{{someCollectionField}}
{{/each}}
</template>
您可以在每个循环中访问把手内的条形值,只需使用.
即可获取内部对象。数组也有效,使用.0
获取数组中的第一项,0是索引。