我需要了解以下显示的问题:
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 create
创建的)上应该至少有2个文件
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();
}
});
}
所以我认为发生的事情是你没有在身体上包括模板。
如果有什么不清楚的地方,请告诉我。