#错误提示:thirdScriptError:
Cannot read property 'songlist' of undefined;at api request success callback function
TypeError: Cannot read property 'songlist' of undefined
#源代码:
// 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) {
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({
board: e.data.showapi_res_body_pagebean.songlist[0].albumpic_big,
songlist: songlist,
loading: false
});
wx.setStorageSync('songlist', songlist);
}
}
});
}
})