基础库更新后That.setData不可用
同样的that.setData代码如下:
that.setData({ examlist: 222, siteUrl: app.globalData.siteBaseUrl }); |
切换到1.4.4及一下版本可用,但在1.5.0及以上版本就不可用,请问这是为什么?
7 回复
const https = require( '../../public/js/douban.js' ); var Util = require( '../../utils/util.js' ); var htmlToWxml = require( '../../utils/htmlToWxml.js' ); var WxSearch = require( '../wxSearch/wxSearch.js' ) if (!Object.assign) { Object.assign = require( '../../public/core/object-assign.js' ) } //获取应用实例 var app = getApp(); Page({ data: { showAddArticleBtn: true , isLoading: false , //加载 page: 1, total: 0, perpage: 10, modalHidden: true , }, onLoad(params) { var that = this ; var accesstoken = app.globalData.token; if (!accesstoken) { app.getUserInfo( function () { that.getAuditList(); }) } else { that.getAuditList(); } }, getAuditList: function () { var that = this ; var page = that.data.page; if (page == 1) { that.setData({ examlist: [], siteUrl: app.globalData.siteBaseUrl }); } https.chapter( 'api/v1/exam_list?page=' + page, null ).then((data) => { if (data.data.code == 0) { console.log( '数据' , data.data.data.count) //更新数据 that.setData({ total: data.data.data.count, examlist: that.data.examlist.concat(data.data.data.exams.map( function (item) { item.updated_at = Util.getDateDiff( new Date(item.updated_at)); item.description = htmlToWxml.html2json(item.description); item.created_at = Util.getDateDiff( new Date(item.created_at)); return item; })) }); setTimeout( function () { that.setData({ isLoading: true }); }, 300); } if (data.statusCode == 401) //token 过期 { this .globalData.token= '' ; app.getUserInfo(); console.log( '401' ) } if (data.statusCode == 400) //没有token { this .globalData.token = '' ; app.getUserInfo(); console.log( '400' ) } else { } }) }, onUnload() { //页面卸载 } }); |
更新下源码,应该是:
that.setData({ total: data.data.data.count, examlist: that.data.examlist.concat(data.data.data.exams.map( function (item) { item.updated_at = Util.getDateDiff( new Date(item.updated_at)); item.description = htmlToWxml.html2json(item.description); item.created_at = Util.getDateDiff( new Date(item.created_at)); return item; })) }); |
问题应该是出在examlist上,
1.4.4及以下版本可用,但在1.5.0及以上版本就不可用