当前位置:网站首页>Getting started with applet cloud development - getting user search content
Getting started with applet cloud development - getting user search content
2022-07-06 03:12:00 【TaylorZ9826】
1. Let's make a nice search box first ( I'm whoring for nothing here )
wxml Remember to define the page to get the user input data getKey() Methods and Click event of search button goSearch()
<view class='page_row'>
<view class="search">
<view class="df search_arr">
<icon class="searchcion" size='20' type='search'></icon>
<input placeholder=" Please enter keywords " bindinput="getKey"></input>
</view>
</view>
<view class='sousuo' bindtap="goSearch"> Search for </view>
</view>
Some corresponding styles :
.search{
width: 80%;
}
.search_arr {
border: 1px solid #d0d0d0;
border-radius: 10rpx;
margin-left: 20rpx;
}
.search_arr input{
margin-left: 60rpx;
height: 60rpx;
border-radius: 5px;
}
.bc_text {
line-height: 68rpx;
height: 68rpx;
margin-top: 34rpx;
}
.sousuo {
margin-left: 15rpx;
width: 15%;
line-height: 150%;
text-align: center;
border: 1px solid #d0d0d0;
border-radius: 10rpx;
}
.page_row{
display: flex;
flex-direction: row
}
.searchcion {
margin: 10rpx 10rpx 10rpx 10rpx;
position: absolute;
left:25rpx;
z-index: 2;
width: 20px;
height: 20px;
text-align: center;
}
2. To write getKey() and goSearch() Method , Minute input is empty 、 If it is not empty
Page({
data:{
key:null
},
getKey(e){
//console.log(e.detail.value) Get the data from the keyboard
this.setData({
key:e.detail.value
})
},
goSearch(){
console.log(this.data.key)
if(this.data.key){
console.log(' You can perform a search ')
}else{
// The search content is empty
wx.showToast({
icon:'error',
title:' Please enter the search content '
})
}
}
})
3. Match the search fields to the database , Follow the multi field fuzzy search in the previous section
let db = wx.cloud.database()
let _ = db.command
Page({
data:{
key:null
},
getKey(e){
//console.log(e.detail.value) Get the data from the keyboard
this.setData({
key:e.detail.value
})
},
goSearch() {
console.log(this.data.key)
if (this.data.key) {
console.log(' You can perform a search ')
let key=this.data.key
db.collection('news')
.where(_.or([{ // title
title: db.RegExp({ // Use regular queries , Realize the fuzzy query of search
regexp: key, // The words to search
options: 'i', // Case insensitive
}),
},
{ // describe
desc: db.RegExp({
regexp:key,
options: 'i',
}),
},
{ // Content
content: db.RegExp({
regexp: key,
options: 'i',
}),
}
])).get()
.then(res => {
console.log(' Search successful ', res)
this.setData({
list: res.data
})
})
.catch(res => {
console.log(' Search failed ', res)
})
} else {
// The search content is empty
wx.showToast({
icon: 'error',
title: ' Please enter the search content '
})
}
}
})
4.wxml New search results interface and style
<view wx:if="{
{list&&list.length>0}}">
The search results are as follows :
<view wx:for="{
{list}}" wx:key='index'>
<view class="item">
<view> title :{
{item.title}}</view>
<view> describe :{
{item.desc}}</view>
<view> Content :{
{item.content}}</view>
</view>
</view>
</view>
<view wx:if="{
{list&&list.length==0}}">
The search content is empty
</view>
.item{
margin: 20rpx;
border-bottom: 1px solid gainsboro;
color: gray;
}
5. Realization effect :
边栏推荐
- C language - Blue Bridge Cup - promised score
- 银行核心业务系统性能测试方法
- Is there a completely independent localization database technology
- Leetcode problem solving -- 108 Convert an ordered array into a binary search tree
- Distributed service framework dobbo
- Item 10: Prefer scoped enums to unscoped enums.
- Misc (eternal night), the preliminary competition of the innovation practice competition of the National College Students' information security competition
- Research on cooperative control of industrial robots
- 【Kubernetes 系列】一文學會Kubernetes Service安全的暴露應用
- Data and Introspection__ dict__ Attributes and__ slots__ attribute
猜你喜欢
[kubernetes series] learn the exposed application of kubernetes service security
XSS challenges绕过防护策略进行 XSS 注入
What is the investment value of iFLYTEK, which does not make money?
CobaltStrike-4.4-K8修改版安装使用教程
[network security interview question] - how to penetrate the test file directory through
【若依(ruoyi)】启用迷你导航栏
JS regular filtering and adding image prefixes in rich text
Performance test method of bank core business system
Eight super classic pointer interview questions (3000 words in detail)
1. Dynamic parameters of function: *args, **kwargs
随机推荐
[ruoyi] ztree custom icon (iconskin attribute)
My C language learning records (blue bridge) -- files and file input and output
How to choose PLC and MCU?
华为、H3C、思科命令对比,思维导图形式从基础、交换、路由三大方向介绍【转自微信公众号网络技术联盟站】
深入探究指针及指针类型
Web security SQL injection vulnerability (1)
jsscript
这些不太会
继承day01
Deep parsing pointer and array written test questions
Rust language -- iterators and closures
手写数据库客户端
建模规范:命名规范
Crazy, thousands of netizens are exploding the company's salary
3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标
3857 Mercator coordinate system converted to 4326 (WGS84) longitude and latitude coordinates
[Chongqing Guangdong education] higher mathematics I reference materials of Southwest Petroleum University
resulttype和resultmap的区别和应用场景
Daily question brushing plan-2-13 fingertip life
Performance test method of bank core business system