2016-11-03 66 views
0

我需要一些流星幫助。 我在服務器端創建了一個發佈,在客戶端訂閱之後,我添加了一個幫助器來獲取我的數據。流星幫手修改輸出

this.helpers({ 
     tags() { 
     var tags = Tag.find(); 
     return tags; 
     } 
}) 

我需要做的是添加一個名爲Cheked = true的Key給標籤。 我該怎麼做?因爲如果我在init中執行它,它將無法工作,因爲尚未準備好。

謝謝

回答

0

您可以使用.map()映射光標,添加一鍵每個文檔:

this.helpers({ 
    tags() { 
    let tags = Tag.find().map(doc=>{ 
     doc.checked = true; 
     return doc; 
    }); 
    return tags; 
    } 
}) 
+0

非常感謝Michel,這確實是我需要的。 –

0

嘗試用這種方式:

Template.myTemplateName.helpers({ 
tags(){ 
    //You should use also find().fetch() 
     return Tag.find().fetch(); 
} 
}); 

顯示您的潛艇代碼。 如果要添加關鍵對象,你應該使用

Tag.update(id,{$set: {keyName: value}}) on selected id or all elements. 
+0

謝謝你的評論,但我不't只想在我的控制器中更改集合中的值,所以我不想使用.update –