数组的filter方法

/* 
filter()
对数组中的每个元素都执行一次指定的函数(callback),并且创建一个新的数组,
该数组元素是所有回调函数执行时返回值为 true 的原数组元素。它只对数组中的
非空元素执行指定的函数,没有赋值或者已经删除的元素将被忽略,同时,新创建的
数组也不会包含这些元素。
回调函数可以有三个参数:当前元素,当前元素的索引和当前的数组对象。
*/

Element的远程搜索输入框

<el-form-item label="楼盘名称">
     <el-autocomplete
         v-model="formLabelAlign.houseName"
         :fetch-suggestions="querySearchAsync"
         prefix-icon="iconfont icon-magnifier"
         @select="handleSelect"
         placeholder="请输入楼盘名称">
     </el-autocomplete>
</el-form-item>

script中

async querySearchAsync(queryString, cb) {
      let houseList = this.houseList;
      let results = queryString
        ? houseList.filter((element, index, self)=>{
          return element.value.indexOf(queryString) === 0;
        })
        : houseList;
      cb(results);
    }

猜你喜欢

转载自blog.csdn.net/qq_41834059/article/details/81503461