跳到主要内容

条件查询联系人 (contact.query)

Android 扩展

此函数为 Android 平台扩展,仅在 NBTouch (Android) 上可用。

声明

结果 = contact.query({
id = 联系人ID,
name = 姓名,
phone = 电话号码,
offset = 偏移量,
limit = 限制数量,
})

参数及返回值

  • 联系人ID
    • 整数型,可选,按 ID 精确查询
  • 姓名
    • 文本型,可选,按姓名模糊匹配
  • 电话号码
    • 文本型,可选,按电话号码查询
  • 偏移量
    • 整数型,可选,默认 0
  • 限制数量
    • 整数型,可选,默认 100
  • 结果
    • 文本型,JSON 格式的响应字符串

说明

根据条件查询联系人。参数可组合使用,不传参数则返回所有联系人。

示例

-- 按姓名模糊查询
local result = contact.query({ name = "张" })

-- 按电话号码查询
local result = contact.query({ phone = "138" })

-- 按 ID 精确查询
local result = contact.query({ id = 1 })

-- 组合查询 + 分页
local result = contact.query({
name = "张",
offset = 0,
limit = 10
})

-- 解析结果
local data = json.decode(result)
if data.code == 200 then
for _, c in ipairs(data.data.list) do
print(c._id, c.display_name)
end
end

返回示例

{
"code": 200,
"data": {
"offset": 0,
"limit": 100,
"count": 1,
"list": [
{
"_id": 1,
"display_name": "张三",
"has_phone_number": 1,
"phones": ["13800138000"]
}
]
},
"msg": "OK"
}