element-ui的输入框总结

1.使用搜索框的坑

querySearch(queryString, cb) {
    let likeThis=this;
  let areaKey= {
    "Condition": {
      "LBLongitude": "",
      "LBLatitude": "",
      "RTLongitude": "",
      "RTLatitude": "",
      "ParentId": "",
      "Key": this.addForm.controlArea
    },
    "Page": 1,
    "Size": 100
  };
  this.$http({
      method: 'POST',
    url: 'api/Acs/QueryArea',
    data: areaKey
  }).then(function (resp) {
    console.log(resp);
    let correctAreaNames=[];
    for(let i=0;iData.Result.length;i++){
        correctAreaNames.push({id: resp.data.Data.Result[i].Id,value: resp.data.Data.Result[i].Name})
    }
    likeThis.areaNames=correctAreaNames;
    let areaNames = likeThis.areaNames;
    console.log(areaNames)
    let results = queryString ? areaNames.filter(likeThis.createFilter(queryString)) : areaNames;
    // 调用 callback 返回建议列表的数据
    cb(results);
  });
},
createFilter(queryString) {
  return (areaName) => {
    return (areaName.value.indexOf(queryString.toLowerCase()) === 0);
  };
},
这里面的key 必须是value,要不就会出现bug无法正常显示(
return (areaName.value.indexOf(queryString.toLowerCase()) === 0);
)的value必须和
 correctAreaNames.push({id: resp.data.Data.Result[i].Id,value: resp.data.Data.Result[i].Name})

的value必须都是value,哪怕是相同的key,比如name等等都会出错



你可能感兴趣的:(vue2,element-ui)