微信小程序错误:thirdScriptError
发布于 6 年前 作者 xuewei 8644 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)
  • 预期表现
  • 复现路径
  • 提供一个最简复现 Demo

thirdScriptError:Cannot read property ‘songlist’ of undefined;at api request success callback function
TypeError: Cannot read property ‘songlist’ of undefined.

这是我练习的list.js源代码:

// pages/list/list.js
var config = require('../../config.js');
 
var formatSeconds = function(value) {
  var time = parseFloat(value);
  var m = Math.floor(time / 60);
  var s = time - m * 60;
 
  return [m, s].map(formatNumber).join(':');
 
  function FormatNumber(n) {
    n = n.toString()
    return n[1] ? n : '0' + n
  }
}
 
Page({
  data: {
    board: '',
    songlist: [],
    loading: false,
  },
  onLoad: function(options) {
    var self = this;
    var topid = options.type;
 
    this.setData({
      loading: true
    })
 
    wx: wx.request({
      url: config.config.hotUrl,
      data: {
        topid: topid
      },
      success: function(e) {
        //var songlist=songlist;
        //var self = this;
        if (e.statusCode == 200) {
          var songlist = e.data.showapi_res_body_pagebean.songlist;
 
          for (var i = 0; i < songlist.length; i++) {
            songlist[i].seconds = formatSeconds(songlist[i].seconds);
          }
          self.setData({  //估计是这里出bug
            board: e.data.showapi_res_body_pagebean.songlist[0].albumpic_big,
            songlist: songlist,/** 定位?**/
            loading: false
          });
 
          wx.setStorageSync('songlist', songlist);
        }
      }
    });
  }
 
})
2 回复

请求返回的数据

success中e的值是什么,检查一下,应该是没有对应属性值的,e.data.showapi_res_body_pagebean

如需本文件其他源代码,请告知我。

回到顶部