Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
IraShinking opened this issue Aug 31, 2020 · 0 comments
Open

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

IraShinking opened this issue Aug 31, 2020 · 0 comments

Comments

@IraShinking
Copy link

IraShinking commented Aug 31, 2020

错误主要是报"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函数更新云数据库
@IraShinking IraShinking changed the title create.js中extend针对传入的集合名报错 create.js中 extend函数针对传入的集合名报错 Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant