Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 返回Meteor中的数据问题?_Javascript_Meteor - Fatal编程技术网

Javascript 返回Meteor中的数据问题?

Javascript 返回Meteor中的数据问题?,javascript,meteor,Javascript,Meteor,我需要了解以下问题: JS代码: Template.main.helpers({ ItemName: function() { var self = this; console.log("helpers : " +self.fieldoptions); return _.map(self.fieldoptions,function(p) {

我需要了解以下问题:

JS代码:

 Template.main.helpers({
        ItemName: function() {
            var self = this;
           console.log("helpers : " +self.fieldoptions);
            return _.map(self.fieldoptions,function(p) 
               {
                  p.parent = self;
                 return p;
              });
        }
    });
HTML代码:

 {{#each ItemName}}

        {{this.parent.fname}}                      

   {{/each}}

上面的Js返回代码没有显示html。因此,如何在html中显示上面的返回代码。我对此一无所知。因此,请帮助我?

我不清楚,因此我将写下我认为正在发生的事情。meteor目录中至少应有2个文件(使用
meteor create
创建的文件)

template.main.html
如果您没有使用任何路由器将模板附加到正文中

<head>
   <title>My title</title>
</head>

<body>
  {{> templateMain}}
</body>

<template name="templateMain">
    {{#each ItemName}}
        {{fname}}
    {{/each}}
</template>
所以我认为发生的是你没有在身体上包括模板


如果有不清楚的地方,请告诉我。

哪里定义了
fieldoptions
以及如何定义?fieldoption是集合字段名。@Christian Fritz
FieldNames = new Meteor.Collection('fieldname');

if( Meteor.isServer && FieldNames.find().count() === 0)
  _.each(['one','two','three','four'], function(value, index){ 
      FieldNames.insert({ fname : value, index : index });        
  });

if(Meteor.isClient){
  Template.main.helpers({
      ItemName: function() {

          return FieldNames.find();
      }
  });
}