引用插件 htmlToWxml.js
// xxx.js
var R_htmlToWxml = require('../../util/htmlToWxml.js');//引入公共方法
// xxx.js
onLoad:function(){
var that = this;
wx.request({
url: '',
data: {},
header: {'content-type': 'application/json'},
success: function(res) {
console.log(res.data);
var sherry=res.data;
that.setData({
silen:R_htmlToWxml.html2json(sherry.post.content)
})
}
});
}
3.页面显示
<!-- xxx.wxml -->
<block wx:for="{{silen}}" wx:for-index="idy" wx:for-item="cellData">
<block wx:if="{{cellData.type == 'view'}}">
<view class="p">
<block wx:for="{{cellData.child}}" wx:key="text">
<block wx:if="{{item.type == 'a'}}">
<text class="a" data-seccode="{{item.attr['data-seccode']}}" data-secname="{{item.attr['data-secname']}}" bindtap="stockClick">{{item.text}}</text>
</block>
<block wx:else>
<text>{{item.text}}</text>
</block>
</block>
</view>
</block>
<block wx:if="{{cellData.type == 'img'}}">
<image class="img" data-index="{{idy}}" mode="aspectFit" src="https://www.seo56.cn/{{cellData.attr.src}}" bindload="imageLoad"></image>
</block>
</block>
此方法亲测可用 插件地址:https://github.com/kevenfeng/html-to-wxml
html-to-wxml-master.zip
引用插件 htmlToWxml.js
// xxx.js
var R_htmlToWxml = require('../../util/htmlToWxml.js');//引入公共方法
将html内容转成json数据
// xxx.js
onLoad:function(){
var that = this;
wx.request({
url: '',
data: {},
header: {'content-type': 'application/json'},
success: function(res) {
console.log(res.data);
var sherry=res.data;
that.setData({
silen:R_htmlToWxml.html2json(sherry.post.content)
})
}
});
}
3.页面显示
<!-- xxx.wxml -->
<block wx:for="{{silen}}" wx:for-index="idy" wx:for-item="cellData">
<block wx:if="{{cellData.type == 'view'}}">
<view class="p">
<block wx:for="{{cellData.child}}" wx:key="text">
<block wx:if="{{item.type == 'a'}}">
<text class="a" data-seccode="{{item.attr['data-seccode']}}" data-secname="{{item.attr['data-secname']}}" bindtap="stockClick">{{item.text}}</text>
</block>
<block wx:else>
<text>{{item.text}}</text>
</block>
</block>
</view>
</block>
<block wx:if="{{cellData.type == 'img'}}">
<image class="img" data-index="{{idy}}" mode="aspectFit" src="https://www.seo56.cn/{{cellData.attr.src}}" bindload="imageLoad"></image>
</block>
</block>
html-to-wxml-master.zip