Tencent / westore

小程序项目分层架构

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

create.js中 extend函数针对传入的集合名报错

IraShinking opened this issue · comments

错误主要是报"TypeError: Cannot read property '(我的集合名)' of undefined"
image

看了一下, 主要是在extend函数的Array of Each处报错

我的设置信息:

  1. 集合的读取权限无影响,手动注释extend方法后,能照常传入openid,读写”仅创建者可读写“的集合数据
  2. 集合中有多条数据记录,传入的where仅对openid进行检索
//create.js
function pull(cn, where) {
    return new Promise(function (resolve) {
        globalStore.db.collection(cn).where(where || {}).get().then(res => {
            extend(res, cn)//手动注释掉这一条之后能在页面处的调用打印出数据信息
            resolve(res)
        })
    })
}

function extend(res, cn) {
    console.log('function extend,res,cn',res,cn);//添加该条之后也能打印出完整的集合数据记录和集合名 但下面的forEach仍然报错
    res.data.forEach(item => {
        const mds = globalStore.methods[cn]
        mds && Object.keys(mds).forEach(key => {
            Object.defineProperty(item, key, {
                enumerable: true,
                get: () => {
                    return mds[key].call(item)
                },
                set: () => {
                    //方法不能改写
                }
            })
        })
    })
}

在使用westore cloud的数据库更新功能时,传入了一个数组,同样在Array for Each 处报错:
image

回顾我对更新功能的调用,在使用westore前的demo里,我是在具体页面的onHide函数,通过云函数来更新数据库。使用westore之后,我仍然需要在onHide函数中获取全局数据,并一次上传到数据库,查看create.js 发现:

  1. push函数中使用了update函数的返回值
    2.update函数的返回值是diff后的结果
    3.我的onHide调用中传入的,已经是最新的数据,diff结果自然为空,于是无法使用push函数更新云数据库