1

Meteorでこれを行うにはどうすればよいですか?

Template.foo.bar = function() {


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

}

- - - -レンプレート - -

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

通常のJavaScriptでは、配列を使用して複数の値を返すことができますが、Meteorではどのように機能しますか?

4

1 に答える 1

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 がインデックスです。

于 2013-02-20T20:14:17.020 に答える