1 , list 頁面跳轉到 emp
showEmp(e)
{
let openid = e.currentTarget.dataset.openid;
console.log( "頁面傳參openid:", openid);
// wx.showToast({ title: 'OpenID:'+openid, icon: 'none', duration: 3000 });
//setTimeout(function () { wx.hideToast() }, 2000);
wx.navigateTo({
url: '/pages/emp/emp?openid='+openid,
})
}
2,emp.js onload 內根據openid 查詢資料 然后準備到頁面 顯示
Page({
/**
* 頁面的初始資料
*/
data: {
tiwen:[]
},
/**
* 生命周期函式--監聽頁面加載
*/
onLoad: function (options) {
let openid = options.openid ;
this. getEmpList(openid);
console.log("本周體溫資料 2 :" + this.Data.tiwen );
}
/**
* 獲取指定openid 本周體溫資料
*
*/
getEmpList: function(openid)
{
var now = new Date();
var d1 = now.getFullYear() + "/" + this.getWeek(0);
var d7 = now.getFullYear() + "/" + this.getWeek(7);
let tw=[];
var that=this;
db.collection('emps') .where({
indate: cm.gte(new Date(d1).getTime()).and(cm.lt(new Date(d7).getTime()-3)),
_openid: openid
})
.get({
success: function (res) {
console.log(" 獲取指定openid 溫度資料:", res.data);
for (var i = 0; i < res.data.length; i++) {
console.log(" 體溫 :" + res.data[i].tiwen);
tw[i] = res.data[i].tiwen;
}
console.log("本周體溫資料 1 : " + tw);
that.setData({
tiwen:tw , // 這里報錯
});
}
});
},3/報錯代碼
Cannot read property 'tiwen' of undefined;at "pages/emp/emp" page lifeCycleMethod onLoad function
TypeError: Cannot read property 'tiwen' of undefined
at ye.onLoad (http://127.0.0.1:24981/appservice/pages/emp/emp.js:66:42)
at ye.<anonymous> (WAService.js:1:1353019)
at ye.p.__callPageLifeTime__ (WAService.js:1:1352764)
at Tt (WAService.js:1:1367714)
at WAService.js:1:1369208
at xt (WAService.js:1:1369254)
at Function.<anonymous> (WAService.js:1:1374768)
at i.<anonymous> (WAService.js:1:1344283)
at i.emit (WAService.js:1:445256)
at Object.emit (WAService.js:1:607614)

uj5u.com熱心網友回復:
沙發,大神請進。uj5u.com熱心網友回復:
我也遇到了類似的問題,關鍵就在that.setData({tiwen:tw , <span style="color: #FF0000;"> // 這里報錯</span>
});不知道為什么老說tiwen未定義,期待大神解惑
uj5u.com熱心網友回復:
你把回傳的res列印出來看看,里面有沒有提問欄位轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/53254.html
標籤:微信開發
上一篇:求助關于微信運動資料作弊問題
