在elementUI中使用 el-autocomplete 实现远程搜索的下拉框


          
        

querySearchAsync(queryString, cb) {
        const allCity = this._.cloneDeep(this.cityData);
        const restaurants = allCity;
        const results = queryString ? restaurants.filter(this.createStateFilter(queryString))
          : restaurants;
        console.log(cb(results));
        cb(results);
      },
      createStateFilter(queryString) {
        return restaurants => (restaurants.value
          .toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      },

先贴代码


image.png

image.png

居然打印的 cb(results)是undefined
百度之后才知道


image.png

好吧,只好重新给数组对象
对象的键是改不了的,只好重新加个

for (let i = 0; i < allCity.length; i += 1) {
        allCity[i].value = allCity[i].townName;      
       delete allCity[i].townName;
      }

你可能感兴趣的:(在elementUI中使用 el-autocomplete 实现远程搜索的下拉框)