获取单条数据

操作步骤

1.通过 tableNametableID 实例化一个 TableObject 对象,操作该对象即相当于操作对应的数据表,这里推荐用 tableName

let MyTableObject = new wx.BaaS.TableObject(tableName)

let MyTableObject = new qq.BaaS.TableObject(tableName)

let MyTableObject = new BaaS.TableObject(tableName)

let MyTableObject = new my.BaaS.TableObject(tableName)

let MyTableObject = new swan.BaaS.TableObject(tableName)

参数说明

tableName 和 tableID 二选一,不能同时存在

参数类型必填说明
tableIDNumber数据表的 ID
tableNameString数据表名(SDK >= 1.2.0)

2.指定 recordID 执行获取相应数据项操作

MyTableObject.get(recordID)

参数说明

参数类型必填说明
recordIDString记录 ID

示例

请求示例

  1. let tableName = 'product'
  2. let recordID = '59897882ff650c0477f00485'
  3. let Product = new wx.BaaS.TableObject(tableName)
  4. Product.get(recordID).then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })
  1. let tableName = 'product'
  2. let recordID = '59897882ff650c0477f00485'
  3. let Product = new qq.BaaS.TableObject(tableName)
  4. Product.get(recordID).then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })
  1. let tableName = 'product'
  2. let recordID = '59897882ff650c0477f00485'
  3. let Product = new BaaS.TableObject(tableName)
  4. Product.get(recordID).then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })
  1. let tableName = 'product'
  2. let recordID = '59897882ff650c0477f00485'
  3. let Product = new my.BaaS.TableObject(tableName)
  4. Product.get(recordID).then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })
  1. let tableName = 'product'
  2. let recordID = '59897882ff650c0477f00485'
  3. let Product = new swan.BaaS.TableObject(tableName)
  4. Product.get(recordID).then(res => {
  5. // success
  6. }, err => {
  7. // err
  8. })

返回示例

res 结构如下:

  1. {
  2. "statusCode": 200,
  3. "data": {
  4. "_id": "59a3c2b5afb7766a5ec6e84e",
  5. "amount": 0,
  6. "created_at": 1503904437,
  7. "created_by": 36395395,
  8. "desc": ["good"],
  9. "id": "59a3c2b5afb7766a5ec6e84e",
  10. "name": "apple",
  11. "price": 1.0,
  12. "read_perm": ["user:*"],
  13. "updated_at": 1503904437,
  14. "write_perm": ["user:*"]
  15. }
  16. }

err 对象结构请参考错误码和 HError 对象

常见错误:

错误码 err.code可能的原因
404数据行不存在

字段过滤与扩展

请参考字段过滤与扩展章节