onLoad: function() {
var res_imgurl = wx.getStorageSync("res_imgurl");
var res_data = wx.getStorageSync("res_data");
//res_data = res_data.toString();//强制转换为字符串
res_data.replace(RegExp("http", "g"), "https");//全部替换
console.log("替换后:"+res_data);
res_data = JSON.parse(res_data);
var itemData = res_data["result"];
this.setData({
imgurl: res_imgurl,
itemData: itemData,
result_num: res_data["result_num"]
});
for (var a = this.data.itemData, s = [], e = 0, o = a.length; e < o; e++) {
var i = (100 * Number(a[e].score)).toFixed(2);
s.push(i);
}
this.setData({
score: s
}), console.log(this.data.itemData);
}
显示Cannot read property 'length' of undefined错误,请高手帮忙解决下,谢谢
this.data.itemData的值没有取到,排查一下。
this.setData({},()=>{
})
下面的循环写回调里面
这里
})