Get the App
SLTechnology News&Howtos  ›  Development  › 

How does WeChat Mini Programs realize the search input box with search records

Shulou Source: shulou.com Published: 2022-06-01 06:46:55 09月23日 Update

This article mainly explains "WeChat Mini Programs how to achieve the search input box with search records", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "WeChat Mini Programs how to achieve the search input box with search records" bar!

There is a requirement in the recent project, that is, you need an input box with search records, but you don't need to use the background, so you think of using the local cache setStorageSync.

Summarize the points you need to pay attention to:

1. Reverse the search time.

Unshift: insert data in front of the array and change the array.

2. When spaces are added before and after the search content.

String.trim (); / / remove the spaces before and after

3. Maximum number of search records to be cached.

/ / if there are more than 8 search records, delete the oldest one

If (searchData.length > = 8) searchData.pop ()

/ / pop: deletes the last element of the array.

4. Enter the content that the search record already has.

/ / delete the search record first, and then add the element to the first place

/ / if there are duplicates in the search record, delete it.

For (let I = 0; I < searchData.length; iTunes +) {

If (searchData [I] = = this.data.inputValue.trim ()) {

SearchData.splice (iPol 1)

Break

}

}

/ / add search record

SearchData.unshift (inputValue.trim ())

Only the key code has been uploaded. If you have bug, please check it and modify it. It should not be a big problem.

At this point, I believe you have a deeper understanding of "WeChat Mini Programs how to achieve the search input box with search records". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Search input content programs arrays elements spaces caching learning practical deeper small code reverse key interest background practicality practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Huawei MySQL Docker Linux