initReply(data).then((res) => {
if (res.length > 0) {
res.forEach((v) => {
if (this.hadExpendSonList.includes(v.id)) {
// 如果展开的回复列表id包含了当前回复的id,不做任何操作
} else {
// 如果不在,找出父级
let parentIndex = this.chartList.findIndexOf(a => a.id === v.qisopnCommonsBo) //currentply
// 判断父级是否在展开列表里
if (this.expendList.includes(this.chatList[parentIndex].likeIndex)) {
// 如果父级已经展开,将该条放到replyList子列表最前面
let sonList = [v, ...this.chatList[parentIndex].replyList]
this.$set(this.chatList[parentIndex], 'replyList', sonList)
} else {
// 如果父级未展开,去展开父级
this.expendList.push(this.chartList[parentIndex].likeIndex)
toExpend(this.chartList[parentIndex]).then((response) => {
let idList = response.map((k) => k.id)
this.hadExpendSonList = [...idList, ...this.hadExpendSonList]
this.$set(this.chatList[parentIndex], 'replyList', response)
})
}
}
})
}
})
``1.拿到后端的每条回复的
2.1拿到已经展开的回复子列表的qiscommbo集合
2.2 在foreach循环里对比该条的commsbo有没有在展开集合里。
2.3如果在展开集合里,不做任何操作
2.4如果不在,就得找出父级。。。。再判断父级是否展开
2.5如果父级展开了,将这条放进子列表第一个,并讲common bo放进展开列表。2.6如果父级没展开,就把父级展开。
vue展开评论功能
于 2022-02-16 22:31:37 首次发布