|
@@ -22,13 +22,23 @@ export class PostComponent implements OnInit {
|
|
|
constructor(private router: Router) { }
|
|
|
|
|
|
async ngOnInit() {
|
|
|
+ this.loadPosts(); // 加载帖子
|
|
|
+ }
|
|
|
+
|
|
|
+ async loadPosts() {
|
|
|
const query = new CloudQuery('post'); // 创建查询对象
|
|
|
console.log(query);
|
|
|
query.include('user'); // 包含 user 属性
|
|
|
this.posts = await query.find(); // 使用 find 方法获取所有帖子
|
|
|
console.log(this.posts);
|
|
|
-
|
|
|
-
|
|
|
+ // 获取每个帖子的评论数
|
|
|
+ for (let post of this.posts) {
|
|
|
+ const commentQuery = new CloudQuery('comment');
|
|
|
+ commentQuery.equalTo('post', post.toPointer()); // 根据帖子指针查询评论
|
|
|
+ const comments = await commentQuery.find(); // 获取评论
|
|
|
+ post.commentCount = comments.length; // 将评论数存储在帖子对象中
|
|
|
+ console.log('帖子评论数',post.commentCount);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 用于跟踪点赞状态
|