编程纯纯萌新,想写一个简单的微信小程序,现在通过微信开发助手自带的代码自己修改成这样了
// index.js
// const app = getApp()
const { envList } = require('../../envList.js');
Page({
data: {
showUploadTip: false,
powerList: [{
title: '认定督导管理',
tip: '事中督导、事后督导、竞赛督导',
showItem: false,
item: [{
title: '事中督导',
page: '事中督导'
},
// {
// title: '微信支付'
// },
{
title: '事后督导',
page: '事后督导'
},
{
title:'竞赛督导',
page:'竞赛督导'
}
// {
// title: '发送订阅消息',
// }
]
}, {
title: '数据库',
tip: '职建中心员工专用',
showItem: true,
item: [ {
title: '更新数据',
page: 'updateData'
}, {
title: '查询数据',
page: 'selectData'
} ]
}, {
title: '提交材料',
tip: '督导员、社评机构、企业材料提交',
showItem: false,
item: [{
title: '上传文件',
page: 'uploadFile'
}]
}],
envList,
selectedEnv: envList[0],
haveCreateCollection: false },
onClickPowerInfo(e) {
const index = e.currentTarget.dataset.index;
const powerList = this.data.powerList;
powerList[index].showItem = !powerList[index].showItem;
if (powerList[index].title === '数据库' && !this.data.haveCreateCollection) {
this.onClickDatabase(powerList);
} else {
this.setData({
powerList
});
}
},
onChangeShowEnvChoose() {
wx.showActionSheet({
itemList: this.data.envList.map(i => i.alias),
success: (res) => {
this.onChangeSelectedEnv(res.tapIndex);
},
fail (res) {
console.log(res.errMsg);
}
});
},
onChangeSelectedEnv(index) {
if (this.data.selectedEnv.envId === this.data.envList[index].envId) {
return;
}
const powerList = this.data.powerList;
powerList.forEach(i => {
i.showItem = false;
});
this.setData({
selectedEnv: this.data.envList[index],
powerList,
haveCreateCollection: false
});
},
jumpPage(e) {
wx.navigateTo({
url: `/pages/${e.currentTarget.dataset.page}/index?envId=${this.data.selectedEnv.envId}`,
});
},
onClickDatabase(powerList) {
wx.showLoading({
title: '',
});
wx.cloud.callFunction({
name: 'quickstartFunctions',
config: {
env: this.data.selectedEnv.envId
},
data: {
type: 'createCollection'
}
}).then((resp) => {
if (resp.result.success) {
this.setData({
haveCreateCollection: true
});
}
this.setData({
powerList
});
wx.hideLoading();
}).catch((e) => {
console.log(e);
this.setData({
showUploadTip: true
});
wx.hideLoading();
});
}
});
现在出现一个问题,点击数据库之后会报错,报错界面及内容如下:
[自动热重载] 已开启代码文件保存后自动热重载
VM67 WAServiceMainContext.js:2 TypeError: Cannot read property 'envId' of undefined
at zi.onClickDatabase (VM1441 index.js:124)
at zi.onClickPowerInfo (VM1441 index.js:76)
at Object.i.safeCallback (WASubContext.js?t=wechat&s=1709087247850&v=2.20.3:2)
at WASubContext.js?t=wechat&s=1709087247850&v=2.20.3:2
at Ir (WASubContext.js?t=wechat&s=1709087247850&v=2.20.3:2)
at WASubContext.js?t=wechat&s=1709087247850&v=2.20.3:2
at h (WASubContext.js?t=wechat&s=1709087247850&v=2.20.3:2)
at WASubContext.js?t=wechat&s=1709087247850&v=2.20.3:2
at VM67 WAServiceMainContext.js:2
at s (index.js:1)(env: Windows,mp,1.06.2401020; lib: 2.20.3)
errorReport @ VM67 WAServiceMainContext.js:2
thirdErrorReport @ VM67 WAServiceMainContext.js:2
(anonymous) @ VM67 WAServiceMainContext.js:2
(anonymous) @ VM67 WAServiceMainContext.js:2
请大佬们支援