vue.js - Wuxt (Nuxt/Vue) 根据父/子对 v-for 中的项目进行排序
问题描述
我想对从 WP 数据库获取评论的 v-for 循环中的项目进行排序,但是数据库存储具有顺序 ID 的评论,并且由于对某些评论有回复,因此它们的顺序混乱了。
我想要正确的顺序,由comment.parent 属性表示,并且顺序是子评论应该在父母之下。条件类“commentreplied”应该足以缩进 div 以使其在视觉上组合。
到目前为止,这是我的代码:
<div v-for="comment in commentArray" :key="comment.id" :class="{'commentreplied' : comment.parent !== 0 }" class="commentblock">
<img :src="comment.author_avatar_urls['96']" />
<h3>{{ comment.author_name }}</h3>
<div class="comment-body" v-html="comment.content.rendered"></div>
</div>
pastebin 中的评论 JSON https://pastebin.com/vpgy1btw
解决方案
推荐阅读
- python - 使用 RegEx 抓取特定标签元素
- javascript - javascript输出相同的分数两次而不是每次加一个(关闭)
- angular - Angular Material 表单验证在首次提交后停止工作。提交后如何重置表单字段和验证器?
- powershell - Get-ChildItem 命令PowerShell中的内存不足异常
- python - 在 Django 模板上没有呈现任何内容
- python - 将函数中的默认参数值设置为另一个参数的值
- node.js - express/node.js — req.getHeader 不是一个函数
- c# - 如何在 Windows 上防止全屏/半屏
- tinkerpop - yEd Graph Editor 无法打开从 tinkerpop 生成的 Graphml
- laravel - Spatie 媒体库执行转换