success 回调的结果及 Promise resolve 的结果 Result 是一个如下结构的对象:
字段 | 类型 | 说明 |
---|---|---|
data | Array | 查询的结果数组,数据的每个元素是一个 Object,代表一条记录 |
示例代码 1
获取我的待办事项清单
回调风格
const db = wx.cloud.database()
db.collection('todos').where({
_openid: 'xxx' // 填入当前用户 openid
}).get({
success: function(res) {
console.log(res.data)
}
})
Promise 风格
const db = wx.cloud.database()
db.collection('todos').where({
_openid: 'xxx' // 填入当前用户 openid
}).get().then(res => {
console.log(res.data)
})
示例代码 2:分页取数据
获取我的第二页的待办事项清单,假设一页 10 条,现在要取第 2 页,则可以指定 skip 10 条记录
// Promise 风格
const db = wx.cloud.database()
db.collection('todos')
.where({
_openid: 'xxx', // 填入当前用户 openid
})
.skip(10) // 跳过结果集中的前 10 条,从第 11 条开始返回
.limit(10) // 限制返回数量为 10 条
.get()
.then(res => {
console.log(res.data)
})
.catch(err => {
console.error(err)
})
标签:微信小程序
相关阅读 >>
微信小程序使用moveto把路径移动到画布中的指定点,不创建线条
更多相关阅读请进入《微信小程序》频道 >>

Vue.js 设计与实现 基于Vue.js 3 深入解析Vue.js 设计细节
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者