日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

微信小程序页面搜索框查询(无后台接口情况下)

發布時間:2025/3/21 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 微信小程序页面搜索框查询(无后台接口情况下) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

微信小程序頁面搜索框查詢(無后臺接口情況下)

效果圖:

wxml

<view class="container"><view class="goodslist"><view class="search"><view class="search-header"><image src="/news/img/search.png"></image><input class="search-input" bindinput='query' placeholder="搜索"/></view></view><scroll-view scroll-y="true"><view wx:for="{{list}}" wx:key="index" class="goodslist-li" bindtap="onGoodsDetail"><view class="goodslist-li-pic"><image src="{{item.pic}}"></image></view><view class="goodslist-li-content"><view class="goodslist-li-name">{{item.coding}}<text decode="true">&nbsp;</text>{{item.name}}</view><view class="goodslist-li-format">{{item.format}}</view><view class="goodslist-li-factory">{{item.factory}}</view></view></view></scroll-view></view> </view>

js

//index.js //獲取應用實例 const app = getApp()Page({data: {//這是頁面需要的jsonlist: [{'id':'1','pic':'/pages/news/img/banner3.png','coding':'15436','name':'小兒熱速清顆粒','format':'2g*6袋','factory':'哈爾濱圣泰生物制藥有限公司'},{'id':'2','pic':'/pages/news/img/banner3.png','coding':'15436','name':'夏桑菊','format':'10g*15袋','factory':'廣州白云山制藥有限公司'},], //這是查詢需要的jsonlist2: [{'id':'1','pic':'/pages/news/img/banner3.png','coding':'15436','name':'小兒熱速清顆粒','format':'2g*6袋','factory':'哈爾濱圣泰生物制藥有限公司'},{'id':'2','pic':'/pages/news/img/banner3.png','coding':'15436','name':'夏桑菊','format':'10g*15袋','factory':'廣州白云山制藥有限公司'},] },// 搜索query(e){console.log('111')var list = this.data.list2; //先把第二條json存起來var list2 = []; //定義一個數組//循環去取數據for(var i=0;i<list.length;i++){var string = list[i].name;//查詢json里的name是否包含搜索的關鍵詞,如果有就把他裝進list2數組if(string.indexOf(e.detail.value) >= 0){list2.push(list[i]);}}//到這里list2就已經是你查出的數據//如果輸入的關鍵詞為空就加載list數據,不是空就加載list2數據if(e.detail.value == ""){//加載全部this.setData({list: list})} else {this.setData({list: list2})}},// 點擊商品詳情onGoodsDetail:function(){wx.navigateTo({url: '/pages/goods_detail/index'})} })

wxss

/**index.wxss**/ .container{display: flex;flex-direction: column;align-items: center; } /*搜索樣式 */ .search{position: fixed;top: 0;left: 0;width: 100%;height: 100rpx;background-color: #ffffff;border-bottom: 2rpx solid #eeeeee;z-index: 99; } .search-header{width: 95%;height: 70rpx;background-color: #eeeeee;display: flex;justify-self: start;align-items: center;border-radius: 10rpx;margin: 0 auto;margin-top: 15rpx; } .search-header image{width: 50rpx;height: 50rpx;padding: 0 20rpx; } .search-input{width: 80%;height: 70rpx;font-size: 24rpx; } /* 商品列表 */ .goodslist{width: 100%;display: flex;align-items: center;flex-direction: column;background-color: #fff;margin-top: 100rpx; } .goodslist-li{width: 100%;display: flex;justify-content: flex-start;align-items: center;padding: 20rpx 0;padding-left: 20rpx;border-bottom: 2rpx solid #eeeeee; } .goodslist-li-pic{width: 200rpx;height: 200rpx; } .goodslist-li-pic image{width: 100%;height: 100%; } .goodslist-li-content{margin-left:20rpx;font-size: 26rpx;line-height: 50rpx; }

總結

以上是生活随笔為你收集整理的微信小程序页面搜索框查询(无后台接口情况下)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。