返回Meteor中的数据问题?

时间:2014-04-14 15:11:55

标签: javascript meteor

我需要了解下面显示的问题:

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.So如何在HTML中显示上面的返回代码。我对此没有任何了解。所以请帮帮我?

1 个答案:

答案 0 :(得分:0)

我不清楚所以我会写出我认为正在发生的事情。您的meteor目录中应至少有2个文件(使用meteor create创建的文件)

template.main.html如果你没有使用任何路由器使模板附加到正文应该看起来像

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

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

<template name="templateMain">
    {{#each ItemName}}
        {{fname}}
    {{/each}}
</template>

template.main.js围绕这些行

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();
      }
  });
}

所以我认为发生的事情是你没有在身体上包含模板。

如果不清楚,请告诉我。