diff --git a/pages/chose-city/chose-city.vue b/pages/chose-city/chose-city.vue index 189d361..3e80905 100644 --- a/pages/chose-city/chose-city.vue +++ b/pages/chose-city/chose-city.vue @@ -384,20 +384,17 @@ export default { this.mescroll && this.mescroll.triggerDownScroll() }, search() { - if(this.keyword === '') return - const matchIndex = this.listGroup.findIndex((group, index) => { - let result - group.city.forEach(item => { - result = item.cityName.indexOf(this.keyword, 0) - if (result !== -1) { - this.asideTap(index); - return null; - } - }) - if (result !== -1) { - return result - } + const keyword = (this.keyword || '').trim() + if (!keyword) return + const matchIndex = this.listGroup.findIndex(group => { + const cityList = Array.isArray(group.city) ? group.city : [] + return cityList.some(item => item && item.cityName && item.cityName.indexOf(keyword) !== -1) }) + if (matchIndex !== -1) { + this.keyword = keyword + this.asideTap(matchIndex) + return + } if (matchIndex === -1) { uni.showToast({ title: '未找到该城市,请重新输入城市名称',