Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
你丑我先上
unidocs-zh
提交
fde3bfd0
U
unidocs-zh
项目概览
你丑我先上
/
unidocs-zh
与 Fork 源项目一致
Fork自
DCloud / unidocs-zh
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fde3bfd0
编写于
11月 17, 2022
作者:
C
chenruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs: update jql where example
上级
7c2d9aed
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
90 addition
and
11 deletion
+90
-11
docs/uniCloud/jql.md
docs/uniCloud/jql.md
+3
-1
docs/uniCloud/unicloud-db.md
docs/uniCloud/unicloud-db.md
+87
-10
未找到文件。
docs/uniCloud/jql.md
浏览文件 @
fde3bfd0
...
...
@@ -1176,6 +1176,8 @@ jql支持两种类型的查询条件,以下内容有助于理解两种的区
where内还支持使用云端环境变量,详情参考:
[
云端环境变量
](
uniCloud/jql.md?id=variable
)
在 unicloud-db 组件中使用where查询
[
参考
](
uniCloud/unicloud-db.md?id=where
)
#### 简单查询条件@simple-where
简单查询条件包括以下几种,对应着db.command下的各种
[
操作符
](
https://uniapp.dcloud.net.cn/uniCloud/cf-database?id=dbcmd
)
以及不使用操作符的查询如
`where({a:1})`
。
...
...
@@ -3443,4 +3445,4 @@ module.exports = {
**注意**
-
action上传后可能需要一段时间才会在云端生效,通常是3分钟左右
\ No newline at end of file
-
action上传后可能需要一段时间才会在云端生效,通常是3分钟左右
docs/uniCloud/unicloud-db.md
浏览文件 @
fde3bfd0
...
...
@@ -188,7 +188,7 @@ collection有以下几种形式
where中指定要查询的条件。比如只查询某个字段的值符合一定条件的记录。
组件的where属性,与clientDB的JS API是一致的,且内容较多,所以详见js API中相关
`jql`
文档:
[
详情
](
/uniCloud/
uni-clientDB?id=jsquery
)
组件的where属性,与clientDB的JS API是一致的,且内容较多,所以详见js API中相关
`jql`
文档:
[
详情
](
/uniCloud/
jql.html#where
)
但组件与js API有一个差别,就是组件的属性中若使用js中的变量,需额外注意。
...
...
@@ -233,22 +233,99 @@ where中指定要查询的条件。比如只查询某个字段的值符合一定
this
.
$nextTick
(()
=>
{
this
.
$refs
.
udb
.
loadData
()
})
// 多条件示例
// id = this.tempstr 且 create_time > 1613960340000
// this.sWhere = "id=='" + this.tempstr + "' && create_time > 1613960340000"
// id = this.tempstr 或 name != null
// this.sWhere = "id=='" + this.tempstr + "' || name != null"
}
}
</script>
```
多条件查询示例:
方式1. 使用模板字符串,用${}包裹变量
```
html
<template>
<view>
<unicloud-db
ref=
"udb"
collection=
"uni-id-users"
where=
"`id==${this.tempstr} && create_time > 1613960340000`"
></unicloud-db>
</view>
</template>
<script>
export
default
{
data
()
{
return
{
tempstr
:
'
123
'
}
}
}
</script>
```
方式2. 使用js拼接字符串
```
html
<template>
<view>
<unicloud-db
ref=
"udb"
collection=
"uni-id-users"
:where=
"sWhere"
loadtime=
"manual"
></unicloud-db>
</view>
</template>
<script>
export
default
{
data
()
{
return
{
tempstr
:
'
123
'
,
sWhere
:
''
}
}
onLoad
()
{
// id = this.tempstr 且 create_time > 1613960340000
this
.
sWhere
=
"
id=='
"
+
this
.
tempstr
+
"
' && create_time > 1613960340000
"
// id = this.tempstr 或 name != null
// this.sWhere = "id=='" + this.tempstr + "' || name != null"
// 组件上配置了 loadtime = "manual", 这里需要手动加载数据
this
.
$nextTick
(()
=>
{
this
.
$refs
.
udb
.
loadData
()
})
}
}
</script>
```
上述示例使用的是==比较符,如需进行模糊搜索,则使用正则表达式。插件市场提供了完整的云端一体搜索模板,搜索类页面无需自行开发,可直接使用。
[
详见
](
https://ext.dcloud.net.cn/plugin?id=3851
)
再次强调,where条件内容较多,组件和api用法相同,完整的where条件文档在api文档中,另见:
[
JQL文档
](
/uniCloud/uni-clientDB?id=jsquery
)
使用正则模糊查询示例:
```
html
<template>
<view
class=
"content"
>
<input
@
input=
"onKeyInput"
placeholder=
"请输入搜索值"
/>
<unicloud-db
v-slot:default=
"{data, loading, error, options}"
collection=
"goods"
:where=
"where"
>
<view
v-if=
"error"
>
{{error.message}}
</view>
<view
v-else
>
</view>
</unicloud-db>
</view>
</template>
<script>
export
default
{
data
()
{
return
{
searchVal
:
''
}
},
computed
:
{
where
()
{
return
`
${
new
RegExp
(
this
.
searchVal
,
'
i
'
)}
.test(name)`
// 使用计算属性得到完整where
}
},
methods
:
{
onKeyInput
(
e
)
{
// 实际开发中这里应该还有防抖或者节流操作,这里不做演示
this
.
searchVal
=
e
.
target
.
value
}
}
}
</script>
```
再次强调,where条件内容较多,组件和api用法相同,完整的where条件文档在api文档中,另见:
[
JQL文档
](
/uniCloud/jql.html#where
)
## orderby
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录