<el-autocomplete placeholder="请输入城市名"
v-model="cityName"
:fetch-suggestions="querySearchAsync"
class="input-city">
<el-button slot="append" icon="el-icon-search"></el-button>
</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);
},
先贴代码
居然打印的 cb(results)是undefined
百度之后才知道
好吧,只好重新给数组对象
对象的键是改不了的,只好重新加个
for (let i = 0; i < allCity.length; i += 1) {
allCity[i].value = allCity[i].townName;
delete allCity[i].townName;
}