获取数据项
只能通过 Table 对象获取一个记录项 Record 实例,Table 对象提供三种获取记录项:
createRecord(): 创建一个空的记录项。getWithoutData(recordId: xxxx): 获取一个只有 Id 的记录项。get(recordId) { }: 从知晓云获取指定 Id 的记录详情。
创建一个空的数据项
let record = table.createRecord()
BaaSRecord *record = [table createRecord];
该方法常用于新增数据项和批量更新数据,先创建一个空的数据项,设置记录值,并将这些记录信息上传到知晓云数据表。详见 新增数据项
获取一个只有 Id 的数据项
let record = table.getWithoutData(recordId: xxxx)
BaaSRecord *record = [table getWithoutDataWithRecordId: xxxx];
该方法常用于更新一条记录项,先获取一个只有 Id 的数据项,并设置记录值。详见 更新数据项
获取数据项详情
示例代码
let select = ["name", "created_by"]
let expand = ["created_by"]
table.get("5caae446ce8e9e5be81bba48", select: select, expand: expand) { (record, error) in
}
NSArray *select = @[@"color", @"created_by"];
NSArray *expand = @[@"created_by"];
[_table get:@"5ca47715d625d83705971cec" select:select expand:expand completion:^(BaaSRecord * _Nullable record, NSError * _Nullable error) {
}];
参数说明
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| recordId | String | Y | 记录 Id |
| select | Array |
N | 指定筛选的字段,详见数据表 - 字段过滤章节 |
| expand | Array |
N | 指定扩展的字段,详见数据表 - 字段扩展章节 |
返回结果
| 名称 | 类型 | 说明 |
|---|---|---|
| record | Record | 数据项实例, 关于 Record 类型查看 数据类型 章节 |
| error | NSError | 错误信息,参考错误处理和错误码 |
常见错误:
| 错误码 | 可能的原因 |
|---|---|
| 404 | 数据行不存在 |
字段过滤与扩展
请参考数据表 - 字段过滤章节
访问数据项属性
数据项属性包括内置属性和自定义属性,其中内置属性详见 Record
访问内置字段
record.Id
record.created_by
record.created_at
... // 其他内置字段类似方式获取
record.Id
record.created_by
record.created_at
... // 其他内置字段类似方式获取
访问自定义字段
record.get("keyName")
[record get:@"keyName"];
如果访问了不存在的属性,会返回 nil。
