const categoriesList = {
Business: [
{id: 'accounting', title: 'Accounting'},
{id: 'financial', title: 'Financial'}
],
Cloth: [
{id: 'boutique', title: 'Boutique'},
{id: 'privateSale', title: 'Private sale'},
{id: 'financial', title: 'Financial'}
]
}
const searchInList = (categories, searchString) => {
const result = {}
Object.entries(categories).forEach((category) => {
const categoryName = category[0]
const subCategories = category[1]
subCategories.forEach(subCategory => {
if (subCategory.title.toLowerCase().startsWith(searchString.toLowerCase())) {
if (result[categoryName]) {
return result[categoryName].push(subCategory)
}
result[categoryName] = [subCategory]
}
})
})
return result
}
console.log('check:', searchInList(categoriesList, 'financial'))
class Show extends React.Component {
render() {
return (
<div>
<div>
<ElementList opNames={this.state.opNames} />
</div>
<div>
<AddElement AddBrand={this.AddBrand.bind(this)}/>
</div>
</div>
);
}
}