如何使用meteor访问HTML中的集合对象数据?

时间:2014-04-14 13:51:25

标签: meteor

我需要知道如何在html中访问Collection对象数据,如下所示:

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"]
      }

    ];

在上面的代码中,如何访问html中的 fieldOptions 数据.fieldData被插入到集合中,即集合名称为Fields。我是meteor的新手。所以可以请你建议我做什么?

1 个答案:

答案 0 :(得分:0)

在mongo控制台中:

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}}
像这样的Smth ......