小程序模實(shí)現(xiàn)糊搜索功能
本文實(shí)例為大家分享了小程序模實(shí)現(xiàn)糊搜索功能的具體代碼,供大家參考,具體內(nèi)容如下
1.寫(xiě)好頁(yè)面布局
<!--搜索--> <view class="searchbox"> ? <form bindsubmit="formSubmit"> ? ? <view class="search"> ? ? ? <image class="search-icon" src="{{BaseURL}}/uploadFile/images/search-icon.png"></image> ? ? ? <view class="input-search"> ? ? ? ? <input name="value" placeholder="請(qǐng)輸入名稱(chēng)" bindinput='bindInputName' /> ? ? ? </view> ? ? ? <button formType="submit" class="searchbtn">搜索</button> ? ? </view> ? </form> </view>
2.樣式
/*搜索start*/ ? .searchbox { ? width: 100%; ? height: 40px; ? float: left; ? background: #fff; ? border-bottom: 1px solid #eee; } ? .search { ? width: 80%; ? height: 30px; ? line-height: 30px; ? margin: auto; ? background: #fff; ? margin-top: 5px; ? border: 1px solid #eee; ? font-family: "微軟雅黑"; ? font-size: 14px; } ? .search-icon { ? width: 20px; ? height: 20px; ? float: left; ? margin-left: 5px; ? margin-top: 5px; } ? .input-search { ? width: 60%; ? height: 29px; ? line-height: 29px; ? float: left; ? margin-left: 5px; ? font-family: "微軟雅黑"; ? font-size: 14px; } ? .input-search input { ? width: 100%; ? height: 29px; ? line-height: 29px; ? font-family: "微軟雅黑"; ? font-size: 14px; } ? .searchbtn { ? height: 30px; ? width: 60px; ? line-height: 30px; ? float: right; ? text-align: center; ? font-family: "微軟雅黑"; ? font-size: 14px; ? border-top-right-radius: 4rpx; ? border-bottom-right-radius: 4rpx; ? border-top-left-radius: 0px; ? border-bottom-left-radius: 0px; ? background: #3891f8; ? color: #fff; } ? /*end搜索*/
3.js
/********************搜索s************************/ ? bindInputName: function (e) { ? ? console.log("搜索" + e.detail.value); ? ? var info = this.data.baseList; ? ? var value = e.detail.value, ? ? ? newlists = new Array(); ? ? if (e.detail.value == '') { ? ? ? this.setData({ ? ? ? ? lists: info ? ? ? }) ? ? } else { ? ? ? for (var i = 0; i < info.length; i++) { ? ? ? ? if (info[i].goodsPackageFullName.indexOf(value) >= 0) { ? ? ? ? ? newlists.push(info[i]); //添加搜索到的物品名稱(chēng) ? ? ? ? } ? ? ? } ? ? ? this.setData({ ? ? ? ? lists: newlists ? ? ? }) ? ? } ? }, ? ? //搜索 ? formSubmit: function (e) { ? ? var value = e.detail.value.value, ? ? ? info = this.data.baseList, ? ? ? newlists = new Array(); ? ? if (value == "") { ? ? ? this.setData({ ? ? ? ? lists: this.data.baseList ? ? ? }) ? ? } else { ? ? ? for (var i = 0; i < info.length; i++) { ? ? ? ? if (info[i].goodsPackageFullName.indexOf(value) >= 0) { ? ? ? ? ? newlists.push(info[i]); //添加搜索到的物品名稱(chēng) ? ? ? ? } ? ? ? } ? ? ? this.setData({ ? ? ? ? lists: newlists ? ? ? }) ? ? } ? }, ? /*********************搜索e***************************/ ? ? //獲取盤(pán)點(diǎn)記錄 ? getTheGoodsSaveRecord: function() { ? ? var that = this; ? ? wx.request({ ? ? ? header: { ? ? ? ? "Content-Type": "application/x-www-form-urlencoded" ? ? ? }, ? ? ? method: 'POST', ? ? ? url: app.globalData.BaseURL + 'group/v1/getTheGoodsSaveRecord.html', ? ? ? data: { ? ? ? ? goodsSaveRecordID: that.data.goodsSaveRecordID, ? ? ? }, ? ? ? success: function(res) { ? ? ? ? console.log("獲取待存取:", res.data) ? ? ? ? wx.hideLoading() ? ? ? ? var status = res.data.status; ? ? ? ? var info = res.data.info; ? ? ? ? if (status.indexOf("SUCCESS") == 0) { ? ? ? ? ? that.setData({ ? ? ? ? ? ? lists: info, ? ? ? ? ? ? baseList: info, ? ? ? ? ? }) ? ? ? ? } else { ? ? ? ? ? wx.showToast({ ? ? ? ? ? ? title: '獲取失敗!請(qǐng)重新獲取', ? ? ? ? ? ? icon: 'none' ? ? ? ? ? }) ? ? ? ? } ? ? ? } ? ? }) },
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)搜索功能
- 微信小程序首頁(yè)的分類(lèi)功能和搜索功能的實(shí)現(xiàn)思路及代碼詳解
- 微信小程序搜索組件wxSearch實(shí)例詳解
- 微信小程序下拉框搜索功能的實(shí)現(xiàn)方法
- 小程序?qū)崿F(xiàn)搜索框功能
- 微信小程序?qū)崿F(xiàn)搜索功能并跳轉(zhuǎn)搜索結(jié)果頁(yè)面
- 微信小程序搜索框樣式并實(shí)現(xiàn)跳轉(zhuǎn)到搜索頁(yè)面(小程序搜索功能)
- 小程序?qū)崿F(xiàn)搜索框
- 微信小程序?qū)崿F(xiàn)全局搜索代碼高亮的示例
- 微信小程序?qū)崿F(xiàn)搜索歷史功能
相關(guān)文章
詳解Bootstrap的aria-label和aria-labelledby應(yīng)用
這篇文章主要介紹了詳解Bootstrap的aria-label和aria-labelledby應(yīng)用的相關(guān)資料,需要的朋友可以參考下2016-01-01bootstrap3-dialog-master模態(tài)框使用詳解
這篇文章主要為大家詳細(xì)介紹了bootstrap3-dialog-master模態(tài)框的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08JS實(shí)現(xiàn)動(dòng)態(tài)添加外部js、css到head標(biāo)簽的方法
這篇文章主要介紹了JS實(shí)現(xiàn)動(dòng)態(tài)添加外部js、css到head標(biāo)簽的方法,涉及javascript針對(duì)頁(yè)面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-06-06JavaScript面試Module?Federation實(shí)現(xiàn)原理詳解
這篇文章主要為大家介紹了JavaScript面試Module?Federation實(shí)現(xiàn)原理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10微信小程序模板消息限制實(shí)現(xiàn)無(wú)限制主動(dòng)推送的示例代碼
這篇文章主要介紹了微信小程序模板消息限制實(shí)現(xiàn)無(wú)限制主動(dòng)推送的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08JavaScript數(shù)據(jù)結(jié)構(gòu)與算法之二叉樹(shù)實(shí)現(xiàn)查找最小值、最大值、給定值算法示例
這篇文章主要介紹了JavaScript數(shù)據(jù)結(jié)構(gòu)與算法之二叉樹(shù)實(shí)現(xiàn)查找最小值、最大值、給定值算法,涉及javascript二叉樹(shù)定義、賦值、遍歷、查找等相關(guān)操作技巧,需要的朋友可以參考下2019-03-03