zoukankan      html  css  js  c++  java
  • 小程序模糊搜索(词汇联想)

      // 词汇联想
    //HTML部分
     <block wx:if="{{fuzzySearchList && inputValue}}">
            <view class="fuzzy_search">
                <view class="item" data-keys="{{item.suggest}}" catchtap="doSearch" wx:key="{{index}}" wx:for="{{fuzzySearchList}}">
                    <view class='oneText'>
                        <text wx:for="{{item.suggest}}" wx:key="{{index}}" class="{{item == inputValue ? 'highlight' : '' }}">{{item}}</text>
                    </view>
                </view>
            </view>
        </block>
    
    

    getValue中300毫秒获取模糊搜索(bindinput="getValue"):

    setTimeout(()=>{
        this.searchTap();
    },300)
        // 获取列表
        getFuzzySearchList(kw){
            if (!kw) return Promise.reject(false);
            return new Promise((resolve,reject)=>{
                const _this = this;
                let param = {
                    key_word: kw
                }
                http({
                    url: api.$api.getFuzzySearch,
                    method: 'GET',
                    data: param,
                    success: function(res) {
                        if(res.data.status == 'T'){
                            _this.setData({
                                fuzzySearchList:res.data.data,
                            })
                            resolve()
                        }
                    },
                });
    
            })
        },
        // 处理高亮显示
        searchTap: function (e) {
            this.getFuzzySearchList(this.data.inputValue).then(()=>{
                // let data, newData;
                // data = newData = this.data.fuzzySearchList
                let data = this.data.fuzzySearchList;
                let newData = this.data.fuzzySearchList;
                for (let i = 0; i < data.length; i++) {
                    let dic = data[i];
                    let newDic = newData[i];
                    let name = dic["suggest"];
                    newDic["suggest"] = getInf(name, this.data.inputValue);
                }
                this.setData({
                    fuzzySearchList: newData,
                })
            })
        },
  • 相关阅读:
    字符串-01. 在字符串中查找指定字符(15)
    数组-14. 数字加密(15)
    软考笔记第一天之数制
    基于c#开发的简易点名器
    软考笔记之存储管理
    IO inputStream和outputStream
    java可变参数
    Map集合总结
    Collection集合总结
    Struts 获得前台传参几种方式
  • 原文地址:https://www.cnblogs.com/vonson/p/10796382.html
Copyright © 2011-2022 走看看