Фильтр на основе c результатов поиска - PullRequest
0 голосов
/ 28 февраля 2020

Пожалуйста, обратитесь к изображению ниже,

введите описание изображения здесь Здесь, если я ищу кофе, результат для кофе доступен в трех категориях: машина, пивовар, кофе ... Так что вот если я нажмите на вкладку пивовара, тогда нужно отфильтровать только результат пивовара, так как теперь отображается все содержимое пивовара.

Как я могу отфильтровать данные по содержанию результатов поиска

Здесь мой код.

HTML

<ul class="nav nav-tabs mt-3" role="tablist" *ngIf="showTabs">
    <li class="nav-item" >
      <a class="nav-link active" data-toggle="tab" href="#list" (click)="getAllData()">All</a>
    </li>
    <li class="nav-item"  *ngFor="let items of CoffeeItemList | unique">
      <a class="nav-link" data-toggle="tab" href="#list" (click)="getGlobalSearchList(items.type)">{{items.type | slice:15}}</a>
    </li>
  </ul>

ts

getGlobalSearchList(type: string) {
    this.showLoader = true;
    this.selectedType = type;
    this.CoffeeItemList = [];
    this.getDataListingService.getAllDataLists().subscribe(value => {
        let data = [];
        data = value.data;
        if (this.CoffeeItemList.length === 0) {
          this.noResultFound = true;
      } else {
        this.noResultFound = false;
      }
        console.log(data);
        this.showLoader = false;
        this.noResultFound = false;
        // tslint:disable-next-line:prefer-for-of
        for (let i = 0; i < data.length; i++) {
            if (data[i].type === type) {
                this.CoffeeItemList.push(data[i]);
                this.showTabs = true;
            }
        }
    });
}
getSmartSearchValues(search: string) {
  if (search === '' ) {
      this.getAllData();
      this.noResultFound = false;
      return false;
  }
  if (search.length >= 3) {
    console.log('data');
    this.getDataListingService.searchList(search).subscribe(value => {
        let data = [];
        data = value.data;
        this.CoffeeItemList = value.data;
        this.showLoader = false;
        this.showTabs = true;
        if (this.CoffeeItemList.length === 0) {
          this.noResultFound = true;
      } else {
        this.noResultFound = false;
      }
        // check selected type either coffee, mobile or ALL.
        if (this.selectedType && this.selectedType !== '' ) {
            this.CoffeeItemList = [];
            // tslint:disable-next-line:prefer-for-of
            for (let i = 0; i < data.length; i++) {
                if (data[i].type === this.selectedType) {
                    this.CoffeeItemList.push(data[i]);
                    this.showTabs = true;
                } else {
                  this.noResultFound = true;
                }
            }
        }
    });
  }
}
}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...