账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    求教,微信小程序wxParse的用法?
    54
    0

    小程序新手一枚,在练习的过程中发现接口中内容存在html标签,
    搜索了网上解决方wxParse,参考教程我的代码如下:

    Json是这样的结构:

    {
        "meta": {
            ...
        },
        "pages": [
            {...}
        ],
        "posts": [
            {
                "title": "...",
                "content": "<p>这里是带有html标签的文本。</p>\n"
            },
            
            {
                "title": "...",
                "content": "<p>这里是带有html标签的文本。</p>\n"
            }
        ]
    }

    我的app.js:

    App({
      onLaunch: function (options) {
        var that = this;
        wx.request({
          url: 'https://www.sfatpaper.com/content.json',
          success(res) {
            that.globalData.posts = res.data.posts
          }
        })    
      },
      globalData: {
        posts: ''//传递到子页面
      }
    })

    我的logs.wxml:

    <navigator url="/pages/details/details?id={{item.date}}" class="posts" wx:for="{{posts}}" wx:for-index="idx" wx:for-item="item" wx:key="idx">
      <view class="title">{{item.title}}</view>
      <text>{{item.text}}</text>
    </navigator>

    ----------------通过一楼的回答已对问题作调整,目前问题代码如下--------------------

    我的details.js:

    // pages/posts/posts.js
    var WxParse = require('../../wxParse/wxParse.js');
    const app = getApp();
    Page({
      data: {
        title: '',
        contents: ''
      },
      onLoad: function (options) {
        var that = this;
        that.setData({
          posts: app.globalData.posts
        })
        //筛选数据
        that.data.posts.map(function (item, idx) {
          if (item.date == options.id) {
          
            //套用WxParse开始(此时通过map剩下的应该是唯一的一条内容数据)
            console.log('item.content:'+item.content) //正常的数据
            var parseText = WxParse.wxParse('article', 'html', item.content, that, 5)
            console.log('parseText:' + parseText) //parseText:undefined
            //套用WxParse结束
    
            that.setData({
              title: item.title,
              content: item.content
            })
          }
        })
      }
    })

    点击列表将url中的参数带给详情页,然后详情页通过参数对posts数据进行过滤,最后得出那条唯一的内容,然后进行wxParse,但是不知道什么仍然会报给我 parseText:undefined

    在前台渲染上,页面只渲染了文章的第一个段落。

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部