【发布时间】:2016-11-24 02:17:41
【问题描述】:
topics 是一个返回一些文档的集合。每个文档都有几个字段。其中一个字段是字符串数组。 我试图将字符串数组的值表示为返回的每个文档的单选按钮组。我无法给每个组一个唯一的名称。我尝试了 console.log 语句,发现单选按钮组表现良好,但随后由于调用帮助程序的次数超过返回的文档数而变得混乱。
我的html
<template name=topics>
{{#each topics}}
<tr>
<td><input type="checkbox" name="selectone" id="{{uniqueid}}"/></td>
<td><textarea rows=4 name="topicname" readonly>{{name}} </textarea></td>
<td><input type="text" value="{{dateCreated}}" name="datecreated" readonly/></td>
<td>
{{#each choices}}
{{>radiogroup}}
{{/each}}
</td>
<td><a href="#" name="edittopic">Edit</a></td>
</tr>
{{/each}}
</template>
<template name='radiogroup'>
<li><input type=radio name="{{radiogroupname}}" />{{this}}</li>
</template>
我的js:
Template.topics.helpers({
uniqueid: function() {
Session.set('topicid',this._id);
return this._id;
},
choices:function() {
return this.choices;
},
});
Template.radiogroup.helpers({
radiogroupname: function() {
return(Session.get('topicid'));
},
});
【问题讨论】: