欢迎光临,了解微信小程序开发,就上易用通!

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

发布:2018-01-25 08:49浏览: 来源:网络 作者:tianshu

  1. 引用插件 htmlToWxml.js
 

	
  1. // xxx.js
  2. var R_htmlToWxml = require('../../util/htmlToWxml.js');//引入公共方法
  1. 将html内容转成json数据
 

	
  1. // xxx.js
  2. onLoad:function(){
  3. var that = this;
  4. wx.request({
  5. url: '',
  6. data: {},
  7. header: {'content-type': 'application/json'},
  8. success: function(res) {
  9. console.log(res.data);
  10. var sherry=res.data;
  11. that.setData({
  12. silen:R_htmlToWxml.html2json(sherry.post.content)
  13. })
  14. }
  15. });
  16. }

3.页面显示

 

	
  1. <!-- xxx.wxml -->
  2. <block wx:for="{{silen}}" wx:for-index="idy" wx:for-item="cellData">
  3. <block wx:if="{{cellData.type == 'view'}}">
  4. <view class="p">
  5. <block wx:for="{{cellData.child}}" wx:key="text">
  6. <block wx:if="{{item.type == 'a'}}">
  7. <text class="a" data-seccode="{{item.attr['data-seccode']}}" data-secname="{{item.attr['data-secname']}}" bindtap="stockClick">{{item.text}}</text>
  8. </block>
  9. <block wx:else>
  10. <text>{{item.text}}</text>
  11. </block>
  12. </block>
  13. </view>
  14. </block>
  15. <block wx:if="{{cellData.type == 'img'}}">
  16. <image class="img" data-index="{{idy}}" style="height: {{cellData.attr.height?cellData.attr.height:0}}px" mode="aspectFit" src="{{cellData.attr.src}}" bindload="imageLoad"></image>
  17. </block>
  18. </block>

此方法亲测可用  插件地址:https://github.com/kevenfeng/html-to-wxml 

后台传回的json数据含有html标签,无法在wxml正确显示(图1) html-to-wxml-master.zip





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。