Problem Description: Alipay applet, rich-text attributes of nodes only support the use of Array type, if you need support HTML String, you need to own the HTML String into an array of nodes
Solution: Use mini-html-parser2
Code Sample:
index.axml
<rich-text type="text" nodes="{{htmlData}}"></rich-text>
index.js
import parse from 'mini-html-parser2';
Page({
data: {
htmlData: []
},
onLoad: function (options) {
var that = this;
was strhtml =
<div><span>table test</span><table><thead><tr><th>title</th><th>title</th></tr></thead><tbody><tr><td colspan="2">yy</td><td>xx</td></tr></tbody></table></div></div>`
;
`<div><span>test</span>
Parson (strhtml (err, htmlData) => {
if (!err) {
that.setData({
htmlData
});
}
})
}
})
Note:
HTML string in the label must be closed, otherwise it will not turn an array of nodes, such as: <br> it must be <br/>
import parse from 'mini-html-parser2', there is provided a mounting advance mini-html-parser2 to small root directory, the installation code npm install mini-html-parser2 --save (cmd command line installation, first cd jump to the small program directory, in order to perform the installation)
If the computer does not npm install, please refer
https://blog.csdn.net/wjnf012/article/details/80422313
first installed npm
Reference mounting assembly
https://blog.csdn.net/mentalitys/article/details/89400478