uniapp搜索功能(indexOf)与切割搜索功能(slice)

一.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=[]
  }
},

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gz.ronin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值