萌新提问:微信小程序

编程纯纯萌新,想写一个简单的微信小程序,现在通过微信开发助手自带的代码自己修改成这样了

// 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

请大佬们支援

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值