2015-12-18 68 views
0

我學習流星,我爲實踐目的構建了一個非常基本的應用程序。 我剛剛安裝了Collection FS,並且使用cfs:filesystem上傳文件。 我有一個名爲待辦事項女巫收藏有其中包括以下字段:通過使用Meteor.js迭代MongoDB集合

"files" : [ "/cfs/files/files/HPxaJrEbvNjcnmA6m/files?store=files", "/cfs/files/files/jfKua2BszyfqiKYYu/files?store=files" ] 

該插件通過方法做了服務器端:

'addFiles':function(id,url){ 
    todos.update(id, { 
    $push: {files:url} 
    }); 

我如何可以通過這些迭代,以把他們的網址在我的模板?

我在嘗試的模板是什麼:

{{#each todos}} 
{{#each files}}<a href="{{files}}" target="_blank"> file</a>{{/each}} 
{{/each}} 

的擊打這使得剛剛<a target="_blank"> file</a> 如果文件對象還沒有得到我不想表現出任何網址值。 我該怎麼做?

回答

1

我假設你正確訂閱todos收集和有幫助:

Template.NAME.helpers({ 
    todos : function(){ 
     return todos.find(); 
    } 
}) 

在模板名稱試試這個:

{{#each todos}} 
    {{#each this.files}} 
    <a href="{{this}}" target="_blank"> file</a> 
    {{/each}} 
{{/each}} 

如果files是空的,那麼什麼都不會顯示。

+0

太棒了!只要SO讓我接受你的答案。非常感謝你!我不知道{{this}}屬性。 – Kostenko