当前位置: 首页 > SEO学院网络营销

后台传回的json数据含有html标签,无法在wxml正确显示,json数据格式

来源:未知 浏览量:109次

引用插件 htmlToWxml.js

后台传回的json数据含有html标签,无法在wxml正确显示

// xxx.js

var R_htmlToWxml = require('../../util/htmlToWxml.js');//引入公共方法

后台传回的json数据含有html标签,无法在wxml正确显示

 

// 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="{{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="{{cellData.attr.src}}" bindload="imageLoad"></image>

</block>

</block>

  html-to-wxml-master.zip  

展开全部内容