分页和排序

分页

使用 limit 和 offset 来控制分页数据:

  • limit 指定该请求返回的结果个数
  • offset 偏移量,指定该请求返回的结果的起始位置

默认 limit 为 20, offset 为 0,我们也可以手动指定 limit 和 offset 来控制。例如,每页展示 100 条数据,需要获取第五页的数据,将 limit 设置为 100、offset 设置为 400 即可。limit 最大可设置为 1000。

  1. var Product = new wx.BaaS.TableObject(tableName)
  2. var query = new wx.BaaS.Query()
  3. query.compare('amount', '>', 0)
  4. Product.setQuery(query).limit(10).offset(0).find().then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })
  1. var Product = new qq.BaaS.TableObject(tableName)
  2. var query = new qq.BaaS.Query()
  3. query.compare('amount', '>', 0)
  4. Product.setQuery(query).limit(10).offset(0).find().then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })
  1. var Product = new BaaS.TableObject(tableName)
  2. var query = new BaaS.Query()
  3. query.compare('amount', '>', 0)
  4. Product.setQuery(query).limit(10).offset(0).find().then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })
  1. var Product = new my.BaaS.TableObject(tableName)
  2. var query = new my.BaaS.Query()
  3. query.compare('amount', '>', 0)
  4. Product.setQuery(query).limit(10).offset(0).find().then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })
  1. var Product = new swan.BaaS.TableObject(tableName)
  2. var query = new swan.BaaS.Query()
  3. query.compare('amount', '>', 0)
  4. Product.setQuery(query).limit(10).offset(0).find().then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })

排序

使用 orderBy 来控制使用升序或降序获取数据列表。

  1. var Product = new wx.BaaS.TableObject(tableName)
  2. var query = new wx.BaaS.Query()
  3. query.compare('amount', '>', 0)
  4. // 升序
  5. Product.setQuery(query).orderBy('created_at').find()
  6. // or
  7. Product.setQuery(query).orderBy(['created_at']).find()
  8. // 降序
  9. Product.setQuery(query).orderBy('-created_at').find()
  10. // or
  11. Product.setQuery(query).orderBy(['-created_at']).find()
  12. // 多重排序
  13. Product.setQuery(query).orderBy(['-created_at', 'created_by']).find()
  14. // 👆先按照 created_at 降序,再按照 created_by 升序排列
  1. var Product = new qq.BaaS.TableObject(tableName)
  2. var query = new qq.BaaS.Query()
  3. query.compare('amount', '>', 0)
  4. // 升序
  5. Product.setQuery(query).orderBy('created_at').find()
  6. // or
  7. Product.setQuery(query).orderBy(['created_at']).find()
  8. // 降序
  9. Product.setQuery(query).orderBy('-created_at').find()
  10. // or
  11. Product.setQuery(query).orderBy(['-created_at']).find()
  12. // 多重排序
  13. Product.setQuery(query).orderBy(['-created_at', 'created_by']).find()
  14. // 👆先按照 created_at 降序,再按照 created_by 升序排列
  1. var Product = new BaaS.TableObject(tableName)
  2. var query = new BaaS.Query()
  3. query.compare('amount', '>', 0)
  4. // 升序
  5. Product.setQuery(query).orderBy('created_at').find()
  6. // or
  7. Product.setQuery(query).orderBy(['created_at']).find()
  8. // 降序
  9. Product.setQuery(query).orderBy('-created_at').find()
  10. // or
  11. Product.setQuery(query).orderBy(['-created_at']).find()
  12. // 多重排序
  13. Product.setQuery(query).orderBy(['-created_at', 'created_by']).find()
  14. // 👆先按照 created_at 降序,再按照 created_by 升序排列
  1. var Product = new my.BaaS.TableObject(tableName)
  2. var query = new my.BaaS.Query()
  3. query.compare('amount', '>', 0)
  4. // 升序
  5. Product.setQuery(query).orderBy('created_at').find()
  6. // or
  7. Product.setQuery(query).orderBy(['created_at']).find()
  8. // 降序
  9. Product.setQuery(query).orderBy('-created_at').find()
  10. // or
  11. Product.setQuery(query).orderBy(['-created_at']).find()
  12. // 多重排序
  13. Product.setQuery(query).orderBy(['-created_at', 'created_by']).find()
  14. // 👆先按照 created_at 降序,再按照 created_by 升序排列
  1. var Product = new swan.BaaS.TableObject(tableName)
  2. var query = new swan.BaaS.Query()
  3. query.compare('amount', '>', 0)
  4. // 升序
  5. Product.setQuery(query).orderBy('created_at').find()
  6. // or
  7. Product.setQuery(query).orderBy(['created_at']).find()
  8. // 降序
  9. Product.setQuery(query).orderBy('-created_at').find()
  10. // or
  11. Product.setQuery(query).orderBy(['-created_at']).find()
  12. // 多重排序
  13. Product.setQuery(query).orderBy(['-created_at', 'created_by']).find()
  14. // 👆先按照 created_at 降序,再按照 created_by 升序排列