一.indexOf()搜索功能(任意字符搜索)
1.搜索框:
<!-- 搜索框 -->
<view style="flex: 10;display: flex;">
<uni-search-bar placeholder="搜索" @confirm="search"
v-model="searchValue"
@cancel="cancel"
@clear="clear" >
</uni-search-bar>
</view>
2.搜索代码:
//搜索框
search(res) {
if(this.current==4){
for(let i=0;i<this.sentList.length;i++){ //表单遍历
console.log(this.sentList.procDefName);
if(this.sentList[i].procDefName.indexOf(res.value)!=-1){ //indexOf搜索函数
this.searchList.push(this.sentList[i]) //res.value是搜索时键入值
}
}
if(this.searchList==0){
uni.showToast({
title:'该项目不存在~',
icon:'none'
})
}
this.selectsent=false
this.newsentlist=this.searchList
this.searchList=[]
}
},
3.取消搜索&清除搜索内容
clear(res) {
if(this.current==0){
this.selectstart=true
this.getstartlist()
}
if(this.current==1){
this.selecttodo=true
this.getTodoList()
}
if(this.current==2){
this.selectdone=true
this.getDoneList()
}
if(this.current==3){
this.selectsend=true
this.getTosendList()
}
if(this.current==4){
this.selectsent=true
this.getSentList()
}
},
cancel(res) {
if(this.current==0){
this.selectstart=true
this.getstartlist()
}
if(this.current==1){
this.selecttodo=true
this.getTodoList()
}
if(this.current==2){
this.selectdone=true
this.getDoneList()
}
if(this.current==3){
this.selectsend=true
this.getTosendList()
}
if(this.current==4){
this.selectsent=true
this.getSentList()
}
},
二.切割搜索(slice)功能(也可以实现,费手)
search(res) {
if(this.current==0){
for(let i=0;i<this.startlist.length;i++){
console.log(this.startlist.name);
if(res.value==(this.startlist[i].name||'').slice(0,res.value.length)
||res.value==(this.startlist[i].name||' ').slice(1,res.value.length+1)
||res.value==(this.startlist[i].name||' ').slice(2,res.value.length+2)
||res.value==(this.startlist[i].name||' ').slice(3,res.value.length+3)
||res.value==(this.startlist[i].name||' ').slice(4,res.value.length+4)
||res.value==(this.startlist[i].name||' ').slice(5,res.value.length+5)
||res.value==(this.startlist[i].name||' ').slice(6,res.value.length+6)
||res.value==(this.startlist[i].name||' ').slice(7,res.value.length+7)
){
this.searchList.push(this.startlist[i])
}
}
if(this.searchList==0){
uni.showToast({
title:'该项目不存在~',
icon:'none'
})
}
this.selectstart=false
this.newstartlist=this.searchList
this.searchList=[]
}
},