2014-04-14 75 views
0

我需要知道在HTML中訪問的集合對象的數據,如下圖所示:如何訪問HTML中的Collectin對象數據使用流星?

var fieldData = [ 

     {fieldName: "Hcare1", 

     fieldOptions: [ "Bike","Car","TV","Radio","etc"] 

     }, 

     {fieldName: "Hcare2", 

     fieldOptions: [ "Bike1","Car1","TV1","Radio1","etc"] 
     }, 

    {fieldName: "Hcare3", 

     fieldOptions: [ "Bike2","Car2","TV2","Radio2","etc"] 
     } 

    ]; 

在上面的代碼如何訪問fieldOptions在html.The fieldData數據插入到一個集合,即收藏集名稱Fields。我對流星很陌生,所以請你建議我該怎麼做?

回答

0

在蒙戈控制檯:

db.foo.findOne().fieldOptions; 
[ "Bike", "Car", "TV", "Radio", "etc" ] 

或者在客戶端:

collectionName.findOne().fieldOptions; 

在JS:

Template.your_layout.helpers({ 
    fieldOptions: function() { 
    Fields.findOne().fieldOptions; 
    } 
}); 

在HTML:

{{#each fieldOptions}} 
    {{this}} 
{{/each}} 

這樣的笑容...

+0

是的,但它返回像一個字符串意味着它顯示自行車,汽車,電視,無線電等像這樣,但我需要得到像數組意味着一個訪問。 – Venkat

+0

試一試HTML: '{{#each array}} {{@index}}:{{this}} {{/ each}}' – none

+0

Look [here](http://handlebarsjs.com/ )。循環瀏覽項目 – none