微信小程序展示富文本内容

引入文件

页面

<import src="../../wxParse/wxParse.wxml"></import>

wxss

@import '../../wxParse/wxParse.wxss';

js

var text = require("../../wxParse/wxParse.js");

单个非数组形式
js

productDetail: function(n) {
	var that = this
    text.wxParse("case", "html", 'html数据', that, 5)
},

wxml

<template is="wxParse" data="{{wxParseData:case.nodes}}"></template>

多个数组形式
js

data: {
    recommend_list_text:[],
    recommend_list:[],
},
getIndexData: function() {
	var that = this
	//res.data.info.recommend_list 为数组
	that.handleGoods(res.data.info.recommend_list, 'recommend_list_text');
},

handleGoods: function(t,texta) {
  var that = this
  for (var a = 0; a < t.length; a++) {
  //sketch 数组中的富文本字段
    text.wxParse('sketch' + a, 'html', t[a].sketch, that, 5);
    if (a === t.length - 1) {
      text.wxParseTemArray(texta, 'sketch', t.length, that);
    }
  }
},

wxml

<view wx:for="{{recommend_list}}" wx:for-index="rls" wx:for-item="recommendlist" wx:key="rl">
    <view class="text2">
      <template is="wxParse" data="{{wxParseData:recommend_list_text[rls]}}"></template>
    </view>
</view>