【发布时间】:2018-01-06 04:19:19
【问题描述】:
我正在尝试加载一个数组(带有简单文本),并尝试在调用它时将其加载到模板上。如何从该特定项目中获取 ID 以获取我存储在其中的数组?
HTML 模板:
<template name="commentMarker">
<div id="viewMarker">
<h3 id="markerTitle">{{markerName}}</h3>
<h6 id="markerCategory">{{markerCategory}}</h6>
<br>
<fieldset>
<legend>Description</legend>
<p>{{markerDescription}}</p>
</fieldset>
<form id="commentForm">
<fieldset>
<legend>Comments</legend>
<input type="text" id="markerId" name="idForComment" value={{markerId}}>
<textarea rows="3" cols="19" name="comment" id="commentArea" placeholder="Insert your comment here..."></textarea>
{{#each comments}}
<p id="oneComment">{{this}}</p>
{{/each}}
</fieldset>
<input type="submit" value="Comment" class="commentButton">
<input type="submit" value="Close" class="exitButton">
</form>
</div>
</template>
JS:
Template.commentMarker.helpers({
comments(){
alert(template.find("#markerId").value);
if(commentArray.length===0) return;
else return commentArray;
}});
这是我将评论插入集合项目的地方,它工作正常
Template.commentMarker.events({
'click .commentButton': function(e, template){
e.preventDefault();
var id = template.find("#markerId").value;
var comment = template.find("#commentArea").value;
Points.update(id, { $push: { comments: comment }});
commentArray = Points.findOne(id).comments;
template.find("#commentArea").value = ' ';
}
我尝试将commentArray 作为全局变量,现在仍然如此。但是我不知道如何从该特定项目中获取 Id,我什至将它的 Id(带有隐藏显示)放入表单中以实际插入评论。但这并不能帮助我显示 cmets,因为我似乎无法在 Template.helpers 中找到该字段 ...
【问题讨论】: