【问题标题】:Explain usage of {{#with}} in meteor JS解释流星 JS 中 {{#with}} 的用法
【发布时间】:2015-04-04 19:42:33
【问题描述】:

我尝试使用 {{#with}} .. {{/with}} 检索此流星助手的查询结果,但模板未获取返回结果的数据。

那么有人可以解释在流星 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>

【问题讨论】:

    标签: javascript meteor meteor-helper


    【解决方案1】:

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

    【讨论】:

    • 太棒了!谢谢!这个新平台让我变笨了,但是在这个相对较新的平台上,作为新手谁不会变笨!但我喜欢这个!
    猜你喜欢
    • 2014-03-22
    • 2012-10-10
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    • 1970-01-01
    • 2016-07-17
    相关资源
    最近更新 更多