1
我在另一個幫助器中使用了一個幫助器。我試圖傳遞一個值'post_id',我從'show_post'helper動態獲取。我想傳遞它,然後在返回一組結果返回給helper的查詢中使用它。出於某種原因,應用程序崩潰。有人可以通過這個指導我。在幫助函數中傳遞變量
{{#each show_post}}
{{posttext}}
{{postedBy}}
{{#each show_comment({{post_id}}) }}
//<--- i am passing the value to helper like this.
<span> <p>{{postedBy}}: <h5>{{commenttext}}</h5>{{createdAt}}</p></span>
{{/each}}
{{/each}}
Template.display_block.helpers({
show_post(){
return PostComment.find({parent: 0},{sort: {createdAt: -1}});
}
});
Template.display_block.helpers({
show_comment(e){
var t1 = e;
var now = PostComment.find({post_id:{$regex:new RegExp(’^’ + t1)}});
return now;
}
});
第一輔助產生一個陣列(蒙戈Db的結果).I要在下一助手使用此數組的元素(即是動態的)。所以我想使用一個變量,它可以保存第一個幫助器的數組元素的值,然後將它傳遞給下一個幫助器。在第二個幫助程序中,我想要傳遞此變量並使用此變量對Mongo查詢中的結果進行排序。我是新來的,所以我無法理解這個實例