If you come in, I believe you will use the wxParse plug- in. If you don’t know it , Baidu will learn it automatically.
As shown in the figure below, this is the effect I want to achieve. Each line is an HTML rich text.
After some Baidu, I found the official list: wxParse multi-data cycle usage method.
But I found that the output result looks like this, which makes me very annoyed.
So after some attempts, I found that it can be solved with index. There are two loops, which are actually looping the same array. I added a for-index to the two for loops to be idx and idx1. When outputting, I make the two equal Just passed, so that we can solve this problem
<block wx:for="{
{issueArr}}" wx:key="*this" wx:for-index="idx">
<block wx:for="{
{replyTemArray}}" wx:key="*this" wx:for-index="idx1">
<block wx:if="{
{idx===idx1}}">
<template is="wxParse" data="{
{wxParseData:item}}" />
</block>
</block>
</block>
JS part:
//自定义数组
var replyArr = ["<text>你好</text>","<text>啊</text>","<text>盆友</text>","!"];
for (let i = 0; i < replyArr.length; i++) {
wxParse.wxParse('reply' + i, 'html', replyArr[i], that);
if (i === replyArr.length - 1) {
wxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
}
}
that.setData({
issueArr: datas
})
Transfer from: https://blog.csdn.net/weixin_42063951/article/details/101701402