目前具体思路是通过轮询构建头像,条件是通过判断评论区条目length。问题是有时依然无法显示评论区头像。以下是目前的代码:
function showAvatar() {
$('.feedbackItem').each(function() {
let avatar = $(this)
.children('.feedbackCon')
.children('span:last')
.html()
avatar = avatar
? avatar.replace('http://', 'https://')
: 'https://pic.cnblogs.com/face/sample_face.gif'
if (env === 'dev') avatar = 'https://www.dummyimage.com/50'
const ele = `
`$(this)
.children('.feedbackCon')
.prepend(ele)
})
}
function poll(condition, callback) {
if (condition) {
callback()
} else {
let count = 1
let intervalId = setInterval(() => {
if (condition) {
callback()
clearInterval(intervalId)
}
if (count === 30) {
clearInterval(intervalId)
}
count++
}, 100)
}
}
// 轮询显示头像
function pollToShow() {
if (pageName() !== 'post') return
poll($('.feedbackListSubtitle').length, showAvatar)
}
请问如何解决呢?