【发布时间】:2016-06-29 20:58:28
【问题描述】:
不知何故,我无法将 cmets 添加到特定帖子。 cmets 未插入到 mongo 数据库中。
Comments = new Mongo.Collection('comments');
Template.comments.helpers({
'comment': function(){
console.log(this._id);
return Comments.find();
}
});
Template.addComment.events({
'click button':function(event){
event.preventDefault();
var madeBy = Meteor.user().username;
var comment = document.getElementById('mycomment').value;
var currentPost = this._id;
Comments.insert({
comment:comment,
createdAt:new Date(),
madeBy:madeBy,
});
document.getElementById('mycomment').value='';
}
});
评论页面的HTML代码是:
<template name="comments">
<h2><b>{{name}}</b></h2>
{{> addComment}}
<ul>
{{#each comment}}
<li>{{comment}}</li>
{{/each}}
</ul>
</template>
<template name='addComment'>
<input type='text' placeholder='Add comment here' name='comment' id ='mycomment'>
<button class="btn btn" type="button" id='btn'>Comment</button>
</template>
这里的 {{name}} 指的是发表评论的帖子的名称。 请帮帮我。谢谢。
【问题讨论】:
标签: javascript mongodb meteor meteor-blaze