提交 fde3bfd0 编写于 作者: C chenruilong

docs: update jql where example

上级 7c2d9aed
......@@ -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分钟左右
......@@ -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.
先完成此消息的编辑!
想要评论请 注册