// 词汇联想
//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, }) }) },
请发表评论