2016-09-26 46 views
0

我要顯示在HTML頁面對象的數組的數組,所以我這樣做:如何打印對象從流星幫手

Template.home.helpers({ 
contents() { 
var contentArray = []; 
var content1 = 
{ 
'contentName': 'test1', 
'contentSize': 'test1', 
'contentType': 'test1', 
}; 
var content2 = 
{ 
'contentName': 'test2', 
'contentSize': 'test2', 
'contentType': 'test2', 
}; 
contentArray.push(content1); 
contentArray.push(content2); 
return contentArray; 
} 
}); 

如何顯示在HTML頁面中的「內容」?

回答

1

你有沒有通過流星教程?這在第二步here中進行了介紹。

對你來說,以下應足以作爲一個基本模型:

<template name="home"> 

    {{#each thing in contents}} 
    <ul> 
     <li>Name: {{thing.contentName}}</li> 
     <li>Size: {{thing.contentSize}}</li> 
     <li>Type: {{thing.contentType}}</li> 
    </ul> 
    {{/each}} 

</template> 

如果這沒有意義這將是最好的通過火焰教程的前幾個步驟先工作。

你可能也想看看大火文檔,特別是#each ... in ... - http://blazejs.org/guide/spacebars.html#Each-in

+0

我解決了這個問題,謝謝! –