저는 Posts
및 Comments
입니다. 나는 React와 Meteor를 사용하여 게시물에 주석을 추가 할 수있는 UI를 구축하려고합니다. 댓글을 제출하면 새 댓글이 표시되고 즉시 사라집니다. 페이지를 새로 고칠 때 새로운 설명이 나타납니다. 코멘트를 추가 한 후유성 : 연결된 레코드 추가가 작동하지 않습니다.
export default createContainer((props) => {
const id = props.params.id;
const postHandle = Meteor.subscribe('post', id);
const isLoading = !postHandle.ready();
Meteor.subscribe('comments.forPost', id);
const post = Posts.findOne(id);
const comments =
isLoading ? [] : Comments.find({_id: { $in: post.comments } }).fetch();
console.log(comments.length);
return {
comments,
isLoading,
question,
};
}, PostShow);
내 console.log
문 인쇄 새 길이, 다음, 이전 번호가 인쇄 내에서
Meteor.publish('post', function(postId) {
return Posts.find(postId);
});
Meteor.publish('comments.forPost', function(postId) {
const post = Posts.findOne(postId);
return Comments.find({_id: { $in : post.comments } });
});
Meteor.methods({
'comments.insert'({ postId, content }) {
check(postId, String);
check(content, String);
const commentId = Comments.insert({
createdAt: new Date(),
userId: this.userId,
content,
});
Posts.update(postId, { $addToSet: { comments: commentId }});
});
내가 createContainer
을 사용하여 구성 요소를 반응한다.
문제가 해결되면 답변을 수락 해주십시오. – MasterAM