2015-04-04 36 views
0

我試圖用{{#with}} .. {{/ with}}檢索這個流星助手的查詢結果,但是模板沒有得到返回結果的數據。解釋流星JS中{{#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> 

回答

1

的問題是,fetch返回與所有的選擇相匹配的文檔的陣列。你必須通過寫fetch()[0]代替fetch()挑頭(只)的文件從該陣列(或使用findOne代替findfetch

+0

太好了!謝謝!這個新的平臺讓我啞巴,但誰沒有得到啞巴在這個相對較新的平臺上是一個新手!但我喜歡這個! – JCm 2015-04-04 11:46:14