2013-02-20 19 views
1

我如何在Meteor中做到這一點?在流星中爲Handle模板返回多個值

Template.foo.bar = function() { 


someVar = return value of some other function 
return SomeCollection and someVar; 

} 

-------模板----

{{#each someCollection}} 
{{someVar}} {{someCollectionField}} 
{{/each}} 

在常規的JavaScript我可以只使用一個數組返回多個值,它是如何在流星工作?

回答

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是索引。

+0

甜......謝謝! – algorithmicCoder 2013-02-20 21:13:21