filterList(): void {
let searchtext = this.state.currentSearchBoxValue;
let searchProperties = this.state.searchBoxOptions.searchProperties;
let list = this.props.list;
if(searchtext != undefined && searchtext != '' && searchtext != null)
{
/* Call filter to filter items that match search criteria */
const filteredList = list.filter(item => {
/* Search for any property where the some() criteria is true for
current item */
return searchProperties.some(searchProperty => {
/* If item value on current searchProperty key includes searchText,
return true. This means some() will return true, and
the "item" will be included in filteredList */
const itemPropertyValue = item[ searchProperty ];
return itemPropertyValue.includes(searchtext);
});
});
/* Filtered result */
console.log(filteredList);
}
}