最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序云開發(fā)實(shí)現(xiàn)搜索功能

 更新時(shí)間:2022年05月22日 15:18:29   作者:Bilkan-studio  
這篇文章主要為大家詳細(xì)介紹了微信小程序云開發(fā)實(shí)現(xiàn)搜索功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

微信小程序云開發(fā)實(shí)現(xiàn)搜索功能,供大家參考,具體內(nèi)容如下

微信小程序使用云開發(fā)實(shí)現(xiàn)搜索功能有兩種情況,一種是簡(jiǎn)單的搜索用關(guān)鍵字來查詢數(shù)據(jù),另一種是模糊查詢關(guān)于關(guān)鍵字的全部數(shù)據(jù)查詢。廢話不用多說直接上代碼部分。

簡(jiǎn)單搜索功能實(shí)現(xiàn)

WXML代碼段

<view class="sousuokuang">
? ? <view class="sousuo">
? ? ? ? <view class="shurukuang">
? ? ? ? ? ? <input type="text" placeholder="搜索" value="" bindinput="GetSearchInput"></input>
? ? ? ? </view>
? ? ? ? <view class="sousuo_anniu" bindtap="ToSearch">
? ? ? ? ? ? <text>搜索</text>
? ? ? ? ? ? <icon type="search" size="20"></icon>
? ? ? ? </view>
? ? </view>
</view>

WXSS代碼段

.sousuokuang {
? ? width: 100%;
? ? height: 100rpx;
? ? display: flex;
? ? flex-direction: column;
? ? align-items: center;
? ? background-color: white;
}
.sousuo {
? ? width: 92%;
? ? height: 100rpx;
? ? display: flex;
? ? flex-direction: row;
? ? align-items: center;
? ? justify-items: center;
}
.shurukuang {
? ? width: 80%;
? ? height: 64rpx;
? ? border-radius: 32rpx;
? ? display: flex;
? ? align-items: center;
? ? justify-content: center;
? ? background-color: #f6f6f6;
}
.shurukuang input {
? ? width: 90%;
? ? height: 100%;
? ? font-size: 32rpx;
}
.sousuo_anniu {
? ? width: 20%;
? ? height: 64rpx;
? ? display: flex;
? ? align-items: center;
? ? justify-content: center;
}
.sousuo_anniu text {
? ? font-size: 30rpx;
}

JavaScript代碼段

const db = wx.cloud.database()
Page({
? ? data: {
? ? ? ? search: ''
? ? },
? ? onLoad: function (options) {

? ? },
? ? GetSearchInput: function(e) {
? ? ? ? this.setData({
? ? ? ? ? ? search: e.detail.value
? ? ? ? })
? ? },
? ? ToSearch: function(e) {
? ? ? ? if(this.data.search == '') {
? ? ? ? ? ? wx.showToast({
? ? ? ? ? ? ? title: '請(qǐng)輸入',
? ? ? ? ? ? ? icon: 'none'
? ? ? ? ? ? })
? ? ? ? ? ? return
? ? ? ? }
? ? ? ? db.collection('輸入你查詢的表名').where({
? ? ? ? ? ? name: this.data.search
? ? ? ? }).get().then(res => {
? ? ? ? ? ? if(res.data.length != 0) {
? ? ? ? ? ? ? ? this.setData({
? ? ? ? ? ? ? ? ? ? shangpinbiao: res.data
? ? ? ? ? ? ? ? })
? ? ? ? ? ? }else {
? ? ? ? ? ? ? ? wx.showToast({
? ? ? ? ? ? ? ? ? title: '未找到商品',
? ? ? ? ? ? ? ? ? icon: 'none'
? ? ? ? ? ? ? ? })
? ? ? ? ? ? }
? ? ? ? })
? ? },
})

模糊搜索功能實(shí)現(xiàn)

WXML代碼段和WXSS代碼段跟簡(jiǎn)單搜索的一樣,JavaScript代碼段如下

Javascript代碼段

const db = wx.cloud.database()
Page({
? ? data: {
? ? ? ? search: ''
? ? },
? ? onLoad: function (options) {

? ? },
? ? GetSearchInput: function (e) {
? ? ? ? this.setData({
? ? ? ? ? ? search: e.detail.value
? ? ? ? })
? ? },
? ? ToSearch: function (e) {
? ? ? ? if (this.data.search == '') {
? ? ? ? ? ? wx.showToast({
? ? ? ? ? ? ? ? title: '請(qǐng)輸入',
? ? ? ? ? ? ? ? icon: 'none'
? ? ? ? ? ? })
? ? ? ? ? ? return
? ? ? ? }
? ? ? ? db.collection('輸入你查詢的表名').where({
? ? ? ? ? ? name: db.RegExp({
? ? ? ? ? ? ? ? regexp: this.data.search,
? ? ? ? ? ? ? ? options: 'i',
? ? ? ? ? ? }),
? ? ? ? }).get().then(res => {
? ? ? ? ? ? if (res.data.length != 0) {
? ? ? ? ? ? ? ? this.setData({
? ? ? ? ? ? ? ? ? ? shangpinbiao: res.data
? ? ? ? ? ? ? ? })
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? wx.showToast({
? ? ? ? ? ? ? ? ? ? title: '未找到',
? ? ? ? ? ? ? ? ? ? icon: 'none'
? ? ? ? ? ? ? ? })
? ? ? ? ? ? }
? ? ? ? })
? ? },
})

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

南靖县| 太仓市| 大英县| 潮安县| 昭通市| 乐都县| 阳新县| 西乌珠穆沁旗| 肃宁县| 民乐县| 达孜县| 当阳市| 新昌县| 怀来县| 灌阳县| 沁水县| 拉孜县| 淳安县| 平塘县| 铅山县| 砚山县| 天门市| 乐东| 武鸣县| 左权县| 定陶县| 工布江达县| 高安市| 长宁县| 保定市| 明光市| 邛崃市| 内丘县| 金华市| 安阳县| 祥云县| 宜春市| 南澳县| 伊通| 克什克腾旗| 沾益县|