2013-02-20 8 views
1

유성에서는 어떻게해야합니까? 일반 자바 스크립트Meteor 핸들 막대 템플릿의 여러 값 반환

Template.foo.bar = function() { 


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

} 

------- 템플릿 ----

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

난 그냥 유성에서 작동합니까 어떻게 여러 값을 반환하는 배열을 사용할 수 있을까?

답변

3

당신은

클라이언트 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> 

당신은 핸들 각 루프 내부에 막대 값에 액세스 할 수있는 JS 객체를 반환하고 그것을 통해 이동 핸들을 사용할 수 있습니다 그리고 내부 객체를 가져 오려면 .을 사용하십시오. 배열도 작동합니다. .0을 사용하여 배열의 첫 번째 항목을 가져옵니다. 0은 인덱스입니다.

+0

달콤한 ... 감사합니다. – algorithmicCoder

관련 문제