新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)小程序教程:微信小程序云開發(fā)API 指定查詢排序條件
Collection.orderBy / Query.orderBy
指定查詢排序條件

方法簽名如下:
function orderBy(fieldName: string, order: string): Collection | Query
方法接受一個必填字符串參數(shù) fieldName 用于定義需要排序的字段,一個字符串參數(shù) order 定義排序順序。order 只能取 asc 或 desc。
如果需要對嵌套字段排序,需要用 "點表示法" 連接嵌套字段,比如 style.color 表示字段 style 里的嵌套字段 color。
同時也支持按多個字段排序,多次調(diào)用 orderBy 即可,多字段排序時的順序會按照 orderBy 調(diào)用順序先后對多個字段排序
示例代碼:按一個字段排序
按進度排升序取待辦事項
const db = wx.cloud.database()
db.collection('todos').orderBy('progress', 'asc')
.get()
.then(console.log)
.catch(console.error)
示例代碼:按多個字段排序
先按 progress 排降序(progress 越大越靠前)、再按 description 排升序(字母序越前越靠前)取待辦事項:
const db = wx.cloud.database()
db.collection('todos')
.orderBy('progress', 'desc')
.orderBy('description', 'asc')
.get()
.then(console.log)
.catch(console.error) 文章題目:創(chuàng)新互聯(lián)小程序教程:微信小程序云開發(fā)API 指定查詢排序條件
文章鏈接:http://m.5511xx.com/article/cddoccp.html


咨詢
建站咨詢
