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

網(wǎng)站的建設(shè)成都創(chuàng)新互聯(lián)公司專注網(wǎng)站定制,經(jīng)驗豐富,不做模板,主營網(wǎng)站定制開發(fā).小程序定制開發(fā),H5頁面制作!給你煥然一新的設(shè)計體驗!已為iso認證等企業(yè)提供專業(yè)服務(wù)。
方法簽名如下:
function orderBy(fieldName: string, order: string): Collection | Query
方法接受一個必填字符串參數(shù) fieldName 用于定義需要排序的字段,一個字符串參數(shù) order 定義排序順序。order 只能取 asc 或 desc。
同時也支持按多個字段排序,多次調(diào)用 orderBy 即可,多字段排序時的順序會按照 orderBy 調(diào)用順序先后對多個字段排序
示例代碼:按一個字段排序
按進度排升序取待辦事項
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
return await db.collection('todos').orderBy('progress', 'asc').get()
}
示例代碼:按多個字段排序
先按 progress 排降序(progress 越大越靠前)、再按 description 排升序(字母序越前越靠前)取待辦事項:
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
return await db.collection('todos')
.orderBy('progress', 'desc')
.orderBy('description', 'asc')
.get()
} 當前題目:創(chuàng)新互聯(lián)小程序教程:微信小程序云開發(fā)服務(wù)端數(shù)據(jù)庫API指定查詢排序條件
網(wǎng)頁路徑:http://fisionsoft.com.cn/article/dpssido.html


咨詢
建站咨詢
