newPage
newPage
  • 发布:2023-06-13 23:59
  • 更新:2023-06-14 11:26
  • 阅读:301

云对象中有两个方法,要使用jql怎么才能等待jql执行到数据才返回

分类:uniCloud

我这样写就报错了: Unexpected token ':'
如果不加await,那么返回的就是promiss,不能获得data


    async generateUserId: function(flag = '') {  
        // const db = uniCloud.database()  
        const dbJQL = uniCloud.databaseForJQL({ // 获取JQL database引用,此处需要传入云对象的clientInfo  
            // clientInfo: this.getClientInfo()  
        })  
        // let res = dbJQL.collection('uni-id-users')  
        //  .where({  
        //      deviceid: "" + 1  
        //  })  
        //  .field('deviceid')  
        //  .get()  
        let res = addDevice(dbJQL)  
        console.log(JSON.stringify(res))  
        // if(res.result.data.length > 0) {  
        //  return res.result.data[0];  
        // }  
        // // 表示错误的  
        // return (MAX_USER_DEVICE_ID + randomInt()) + ""  
        return "success"  
    },
async function addDevice (dbJQL) {  

    let res = await dbJQL.collection('devices')  
    .where({  
        deviceid: "" + 1  
    })  
    .field('deviceid')  
    .get()  
    return res;  

}
2023-06-13 23:59 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

async generateUserId: function(flag = '') {

改成

generateUserId:async function(flag = '') {

newPage

newPage (作者)

我想将第二个方法抽取到一个js文件中,这个时候,就无法进行等待执行了,所以不知道怎么处理

该问题目前已经被锁定, 无法添加新回复