当前位置:网站首页>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 :
边栏推荐
- Fault analysis | analysis of an example of MySQL running out of host memory
- MySQL learning notes-10-tablespace recycling
- The next industry outlet: NFT digital collection, is it an opportunity or a foam?
- Taobao focus map layout practice
- C # create self host webservice
- Audio-AudioRecord Binder通信机制
- IPv6 comprehensive experiment
- [Yu Yue education] basic reference materials of digital electronic technology of Xi'an University of Technology
- MySQL advanced notes
- [ruoyi] ztree custom icon (iconskin attribute)
猜你喜欢
JS regular filtering and adding image prefixes in rich text
My C language learning record (blue bridge) -- on the pointer
Codeforces 5 questions par jour (1700 chacune) - jour 6
Explore pointers and pointer types in depth
[network security interview question] - how to penetrate the test file directory through
【RISC-V】外部中断
微服务间通信
Sign SSL certificate as Ca
Precautions for single chip microcomputer anti reverse connection circuit
Jenkins basic knowledge ----- detailed explanation of 03pipeline code
随机推荐
jsscript
Deep parsing pointer and array written test questions
Prototype design
Pat 1046 shortest distance (20 points) simulation
Modeling specifications: naming conventions
Explore pointers and pointer types in depth
深入探究指针及指针类型
I sorted out a classic interview question for my job hopping friends
[unity3d] GUI control
What is the investment value of iFLYTEK, which does not make money?
Daily question brushing plan-2-13 fingertip life
C language - Blue Bridge Cup - promised score
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
[concept] Web basic concept cognition
Problems encountered in 2022 work IV
Function knowledge points
Is there a completely independent localization database technology
3857 Mercator coordinate system converted to 4326 (WGS84) longitude and latitude coordinates
MySQL Server层四个日志
Atcoder beginer contest 233 (a~d) solution