Meteor无法在JavaScript中访问数组

时间:2015-03-13 04:40:33

标签: javascript meteor

HTML:

的index.html

<head>
    <title>A Site</title>

</head>

<body>

</body>

berkeley.html

<template name="berkeley">
    <div class="container">
        <ul>    
            <!--nothing from the task template is displayed-->
            {{#each tasks}}
                {{> task}} 
            {{/each}} 
        </ul>

        <!--just testing without the template by accessing variable directly; still displays nothing-->
        <ul>
            {{#each tasks}}
                <li>{{fullName}}</li>
            {{/each}}
        </ul>
    </div>

</template>

JavaScript的:

logic.js

Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {
    Template.body.helpers({ 

        tasks: function() { 
            return Tasks.find({}, {sort: {createdAt: -1}}); 
        }

    });
}

当URL为&#39; / berkeley&#39;时,我使用Iron Router渲染Berkeley模板。

HTML似乎无法获取数组tasks,该数组存在于JavaScript中并已填充。

task模板有效,因为如果我排除{{#each tasks}}{{/each}} Meteor能够在task模板中显示静态内容,但在包含时,没有任何内容显示。

以下是Meteorpad:http://meteorpad.com/pad/HLWuxo3wMc54dQP33/Copy%20of%20Leaderboard (整个身体块都没有显示,在这种情况下;我很困惑)

0 个答案:

没有答案