国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Development Preparation
Effect display
Preliminary preparation
realization
Extension
Source code
Summary
Home WeChat Applet Mini Program Development An in-depth explanation of how to implement search functions in mini programs

An in-depth explanation of how to implement search functions in mini programs

Sep 06, 2021 pm 07:25 PM
Applets Search function

How to implement the common search functions of mini programs? The following article will take you step by step to understand the method of implementing the search function in the mini program. I hope it will be helpful to you!

An in-depth explanation of how to implement search functions in mini programs

In the process of developing each small program, it will basically be equipped with a search function. So how is the relatively intelligent search function implemented? After a period of study, I have learned a relatively comprehensive search box function, let’s take a look!

An in-depth explanation of how to implement search functions in mini programs

Development Preparation

Effect display

Let’s take a look at the effect first

An in-depth explanation of how to implement search functions in mini programs

Preliminary preparation

The cloud database imports some data to test the search Frame function

An in-depth explanation of how to implement search functions in mini programs

realization

Create three new pages under the directory

index for The first page of the search box

search is the page used for specific searches

hotsearch is the detailed page of the search content

First of all, let’s take a look at the layout of the index on the first page of the search box. Here we mainly introduce the content of the search box. The other content below will not be described in detail here

An in-depth explanation of how to implement search functions in mini programs

This is the index.wxml code

      <view class="search_1" bindtap="gotoSearch">
          <van-search 
          placeholder="搜索單品" disabled
          />
        </view>
      <view class="search_2">
        <view class="pic" bindtap="list" >
          <image src=""></image>
        </view>
      </view>
    </view>

An in-depth explanation of how to implement search functions in mini programs

This is the search.wxml code of the search box

  <view class="dewu-search">
    <view class="return" >
      <view class="return_pic" bindtap="gotoindex">
        <image ></image>
      </view>
      <view class="txt">搜索</view>
    </view>
  </view>
  <van-search 
      value="{{value}}" 
      show-action 
      placeholder="輸入商品名稱、貨號(hào)"
      bind:clear="onClear" 
      bind:search="onSearch"   
      bind:cancel="oncancel" 
      bind:change="onchange"
      bindtap="input"
      value="{{value}}"
    />
    <block wx:if="results.length > 0">
      <van-cell wx:for="{{results}}" wx:key="_id" title="{{item.title}}"  size="large"  />
    </block>
    <view class="page1" hidden="{{issuggest==true?&#39;hidden&#39;:&#39;&#39;}}" >
        <view class="bd">
          <view class="content">熱門搜索</view>
          <view class="box">
            <view class="items">
              <view class="item" wx:for="{{goods}}"
              wx:key="index"  bindtap="hotsearch" data-id="{{item.id}}"
              >
              {{item.hot}}
              </view>
            </view>
          </view>
        </view>
        <view class="last">
          <view class="content">搜索歷史</view>
          <view class="box">
            <view class="items">
              <view class="item" wx:for="{{historyList}}" wx:key="index" data-id="{{item.id}}" bindtap="gotohistoryList"
              wx:key="index">
                {{item.hot}}
              </view>
            </view>
          </view>
        </view>
    </view>
    <view class="page2"   hidden="{{issuggest==false?&#39;hidden&#39;:&#39;&#39;}}">
      <view class="content1">
        <view class="title" wx:for="{{goods1}}" data-id="{{item.id}}"
              wx:key="index"  bindtap="hotsearch" >
              {{item.hot}}
        </view>
      </view>
    </view>
</view>

js must first be introduced into the cloud database Data

    const db = wx.cloud.database();
    const dewuCollection = db.collection(&#39;dewu&#39;);

To pop up related content when the input box changes, two pages are needed. When there is content input in the input box, the hidden page is displayedhidden="{{ issuggest==false?'hidden':''}}" to determine whether related content pages should appear. Use indexOf to determine whether e.detail (content of the input box) exists in the cloud database. If it exists, then store this data in an array and connect For the previously searched array, use wx.setStorageSync(); to store the data in the input box into storage, and then wx.getStorageSync() to extract the data.

This is the details page that will pop up when there is data in the input box. Click to jump to the product details page

An in-depth explanation of how to implement search functions in mini programs

This is the search box Logic

    if(e.detail.length!=0){
        this.setData({
          issuggest:true,
        })
        var arr = [];
        console.log(this.data.goods.length);
            for (var i = 0; i < this.data.goods.length; i++) {
              if (this.data.goods[i].hot.indexOf(e.detail)>=0) {
                arr.push(this.data.goods[i]);
              }
              this.setData({
              goods1:arr,
           })
          }
    }
    else {
      console.log(&#39;succes&#39;);
      this.setData({
         issuggest:false
      })
    }
  },
    async onSearch(e){
    var arr1=new Array();
    var historyList=new Array();
    var storage=new Array();
    for (let i = 0; i < this.data.goods.length; i++){
      if(e.detail==this.data.goods[i].hot){
        arr1.push(this.data.goods[i]);
        console.log(arr1);
        break
      }
      else{
              arr1.push(e.detail);
              console.log(arr1);
        }
    }
    if(arr1.length>1){
      this.setData({
        storage:arr1.slice(arr1.length-1,arr1.length)
      })
    }
    else{
      console.log(arr1,&#39;要存進(jìn)去的數(shù)據(jù)&#39;);
      this.setData({
        storage:arr1
      })
    }
    if(this.data.historyList !=[]){
      this.data.historyList = this.data.historyList.concat(this.data.storage);//連接
    }
    else{
      this.data.historyList=this.data.storage
    }
   wx.setStorageSync(&#39;historyList&#39;, this.data.historyList);
   this.setData({
    historyList:this.data.historyList
  })
  },

An in-depth explanation of how to implement search functions in mini programs

wx.navigateTo can be used to jump to a detailed page, add a string template, determine the value of the id, and use data to Drive the page and jump to the same page with different data.

wx.navigateTo({
      url: `../hotsearch/hotsearch?id=`+id
    })

Finally, the data needs to be updated

     wx.showLoading({
       title: &#39;數(shù)據(jù)加載中...&#39;,
     })   
     setTimeout(()=>{
      wx.hideLoading()
       this.setData({
          goodsNav: nav,
          goodsList:List,
          recommend:List,
          goods2:this.data.historyList
       })
      },1000)
// console.log(goodsList,&#39;===========&#39;);
   },

Be careful not to forget to introduce the address of the component you need to use in the global json or local page json

    "usingComponents": {
        "van-search":"./miniprogram_npm/@vant/weapp/search/index"
  },

Extension

This function of automatically jumping to the middle of the navigation bar is also very commonly used

An in-depth explanation of how to implement search functions in mini programs

This is the most important part of the wxml codescroll- x="true" Let the navigation bar slide in the horizontal direction scroll-with-animation="true" Let the sliding animate, scroll-into-view="{{scrollTop }}"

      <scroll-view  scroll-x="true"
                 scroll-with-animation="true"
                 style="width:100%;" class="scroll-view_H " 
                 scroll-into-view="{{scrollTop}}">
        <view 
        wx:for="{{goodsNav}}"
        wx:key="index"
        id="{{item.id}}"
        data-index="{{index}}"
        data-type="{{item.type}}"
        bindtap="changegoods"
        class="scroll-view-item_H {{activeNavIndex == index?&#39;active&#39;: &#39;&#39;}}  "
        >
          <text>{{item.text}}</text>
        </view>
      </scroll-view>
    </view>

This is the event bound to the navigation barlet {index, type} = e.currentTarget.dataset;Extract index and type, and then set A count is used as the first few, and then spliced ??to id, and the value of id is passed to scrollTop, so that the navigation bar jumps to scrollTopThis value, this value is in the middle

     console.log(e);
    let {index, type} = e.currentTarget.dataset;
    console.log("index=" +index, "type="+type);
    this.setData({
      activeNavIndex:index
    })
    if (type == &#39;recommend&#39;) {
      this.setData({
        goodsList: this.data.recommend
      })
    } 
    else {
        let goods = this.data.recommend.filter((good) => good.camptype == type )
        this.setData({
          goodsList: goods
        })
        //console.log(this.data.goods)
      }
    
      var index1 = e.currentTarget.dataset.index;
      var count = 2;
      var id = "item"+(index1-count);//拼接id
      if(count == 2 && index1 < 3 || count == 3 && index1 < 2 || count == 4 && index1 < 3){
        id = "item0";
      }
      console.log("下標(biāo)",index1,"---分類id名稱",id)
      this.setData({
        scrollTop: id
      })
    },

The effect can be achieved by adding wxss However, there is a problem with writing like this, that is, when the displayed content is an even number, such as 6, it cannot jump to the middle correctly, and will jump to the position of 3, which will cause a slight deviation. I have not solved this problem yet. , I wonder if anyone knows how to solve this?

Source code

Here is the complete source code of the project. Part of the code is given above. If you are interested, you can check out the complete source code

https: //gitee.com/xinccc/fullstack_huoshan/tree/master/wxapp/dewu

Summary

This is the first time I have written a slightly complete project. Here I mainly introduce the main difficulties I encountered during the development process. Although there are no difficulties in general, It means a lot to me. Having such an experience made me realize that I still have a lot to learn. I am also grateful to the teachers and classmates who helped me with guidance when I had difficulties. If you feel that this article If the article reaches your point, you might as well give me a like, which will be a great encouragement to me. If you guys have any advice, I hope we can discuss and learn together in the comment area.

For more programming-related knowledge, please visit: Introduction to Programming! !

The above is the detailed content of An in-depth explanation of how to implement search functions in mini programs. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Develop WeChat applet using Python Develop WeChat applet using Python Jun 17, 2023 pm 06:34 PM

With the popularity of mobile Internet technology and smartphones, WeChat has become an indispensable application in people's lives. WeChat mini programs allow people to directly use mini programs to solve some simple needs without downloading and installing applications. This article will introduce how to use Python to develop WeChat applet. 1. Preparation Before using Python to develop WeChat applet, you need to install the relevant Python library. It is recommended to use the two libraries wxpy and itchat here. wxpy is a WeChat machine

Implement card flipping effects in WeChat mini programs Implement card flipping effects in WeChat mini programs Nov 21, 2023 am 10:55 AM

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: &lt;!--index.wxml--&gt;&l

Alipay launched the 'Chinese Character Picking-Rare Characters' mini program to collect and supplement the rare character library Alipay launched the 'Chinese Character Picking-Rare Characters' mini program to collect and supplement the rare character library Oct 31, 2023 pm 09:25 PM

According to news from this site on October 31, on May 27 this year, Ant Group announced the launch of the "Chinese Character Picking Project", and recently ushered in new progress: Alipay launched the "Chinese Character Picking-Uncommon Characters" mini program to collect collections from the society Rare characters supplement the rare character library and provide different input experiences for rare characters to help improve the rare character input method in Alipay. Currently, users can enter the "Uncommon Characters" applet by searching for keywords such as "Chinese character pick-up" and "rare characters". In the mini program, users can submit pictures of rare characters that have not been recognized and entered by the system. After confirmation, Alipay engineers will make additional entries into the font library. This website noticed that users can also experience the latest word-splitting input method in the mini program. This input method is designed for rare words with unclear pronunciation. User dismantling

How uniapp achieves rapid conversion between mini programs and H5 How uniapp achieves rapid conversion between mini programs and H5 Oct 20, 2023 pm 02:12 PM

How uniapp can achieve rapid conversion between mini programs and H5 requires specific code examples. In recent years, with the development of the mobile Internet and the popularity of smartphones, mini programs and H5 have become indispensable application forms. As a cross-platform development framework, uniapp can quickly realize the conversion between small programs and H5 based on a set of codes, greatly improving development efficiency. This article will introduce how uniapp can achieve rapid conversion between mini programs and H5, and give specific code examples. 1. Introduction to uniapp unia

Geographical positioning and map display using PHP and mini-programs Geographical positioning and map display using PHP and mini-programs Jul 04, 2023 pm 04:01 PM

Geolocation positioning and map display of PHP and mini programs Geolocation positioning and map display have become one of the necessary functions in modern technology. With the popularity of mobile devices, people's demand for positioning and map display is also increasing. During the development process, PHP and applets are two common technology choices. This article will introduce you to the implementation method of geographical location positioning and map display in PHP and mini programs, and attach corresponding code examples. 1. Geolocation in PHP In PHP, we can use third-party geolocation

How to get membership in WeChat mini program How to get membership in WeChat mini program May 07, 2024 am 10:24 AM

1. Open the WeChat mini program and enter the corresponding mini program page. 2. Find the member-related entrance on the mini program page. Usually the member entrance is in the bottom navigation bar or personal center. 3. Click the membership portal to enter the membership application page. 4. On the membership application page, fill in relevant information, such as mobile phone number, name, etc. After completing the information, submit the application. 5. The mini program will review the membership application. After passing the review, the user can become a member of the WeChat mini program. 6. As a member, users will enjoy more membership rights, such as points, coupons, member-exclusive activities, etc.

HTML, CSS and jQuery: Make a data table with search functionality HTML, CSS and jQuery: Make a data table with search functionality Oct 26, 2023 am 10:03 AM

HTML, CSS and jQuery: Make a data table with search function In modern web development, data table is a frequently used element. In order to facilitate users to find and filter data, adding search functions to data tables has become an essential function. This article will introduce how to use HTML, CSS and jQuery to create a data table with search function, and provide specific code examples. 1. HTML structure First, we need to create a basic HTML structure to accommodate the data table

How to get the applet path How to get the applet path Aug 10, 2023 am 10:48 AM

Methods to obtain the path of the mini program: 1. Call the mini program API to obtain the path. You can use the wx.getStorageInfoSync() method to obtain the local storage path of the mini program; 2. Use a third-party tool to obtain the path. Developers can select "Debug" in the tool. " menu, and then select "View local storage path" to obtain the path information of the mini program; 3. Obtain the path through the file manager, open the file manager, and then find the installation directory of the mini program to obtain the path of the mini program.

See all articles