ts 连并 && 导致错误了貌似

  public search (searchApartmentList: string[], searchRentList: string[], searchResourceList: string[]): void {
    this.searchApartmentList = searchApartmentList;
    this.searchRentList = searchRentList;
    this.searchResourceList = searchResourceList;
    console.log(this.searchApartmentList, this.searchRentList, this.searchResourceList);
    const filterFunc = (item: any) => (this.searchApartmentList.length ? this.searchApartmentList.some((apartment_code: string) => item.apartment_code.indexOf(apartment_code) !== -1) : true) && (this.searchRentList.length ? this.searchRentList.some((rent_status: string) => item.rent_status.indexOf(rent_status) !== -1) : true) && (this.searchResourceList.length ? this.searchResourceList.some((resource_code: string) => item.resource_code.indexOf(resource_code) !== -1) : true);
    const data = this.dataSet.filter((item: any) => filterFunc(item));
    console.log(data);
    if (this.sortName) {
      this.displayData = data.sort((a: any, b: any) => (this.sortValue === 'ascend') ? (a[this.sortName] > b[this.sortName] ? 1 : -1) : (b[this.sortName] > a[this.sortName] ? 1 : -1));
      console.log(this.displayData);
    } else {
      this.displayData = data;
    }
  }

调用的时候应该是空数组的searchReasourceList成了undefined

clipboard.png

变成两项&&就可以了 为什么呢

阅读 1.8k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题