解释 {{#with}} 在 meteor JS 中的用法

Explain usage of {{#with}} in meteor JS

我试图使用 {{#with}} .. {{/with}} 检索这个流星助手的查询结果,但是模板没有获取返回结果的数据。

所以有人可以解释一下在 meteor js 上使用 {{#with}} 空格键的正确方法是什么。我尝试使用 {{#each}} ... {{/each}} 并且它完美地获取了数据。

Template.projectDetail.helpers({

    detail: function(){
        //var project = Session.get("aProject");
        if(Session.get("projectSelected")){
            var project = Project.find({_id: Session.get("projectSelected")}).fetch();
        }

        return project;
    }

});

<template name="projectDetail">
<div class="project">
    {{#with detail}}
    <h4 class="project-title">
        <span>{{name}}</span>
        <i class="glyphicon glyphicon-trash pull-right del"></i>
        <i class="glyphicon glyphicon-plus pull-right add"></i>
    </h4>
    <div class="clearfix"></div>

    <div class="project-description">
        <label>Project description:</label>
        <p>
        {{remarks}}
        </p>
    </div>
    {{/with}}
</template>

问题是 fetch returns 一个数组,其中包含与选择器匹配的所有文档。您必须通过编写 fetch()[0] 而不是 fetch()(或使用 findOne 而不是 findfetch 来从该数组中选择第一个(也是唯一一个)文档。