I tried adding another value (organization.name) to the search bar which was already running successfully, in order to not only filter the list of SearchTerms from organization.topic. But he didn't add it..
const filteredOrganizations = context.allOrganizations.filter((organization) => (organization.topic.searchTerms .map((term) => term.toLowerCase()) .join(" ") || organization.name) .includes(searchText.toLowerCase()))
Here are the relevant parts of my return:
<TableBody> {filteredOrganizations.map((organization) => ( <StyledTableRow key={organization.id}> ...
Hope you have some ideas
P粉7454121162023-09-08 11:29:47
Do not use ||
as you also want to check the organization name.
Just concatenate the strings
const filteredOrganizations = context.allOrganizations.filter(organization => ( organization.topic.searchTerms .map(term => term.toLowerCase()).join(' ') + ' ' + organization.name ) .includes(searchText.toLowerCase()))
P粉0837850142023-09-08 09:42:26
This is the solution:
const filteredOrganizations = context.allOrganizations.filter(organization => { const searchTerms = organization.topic.searchTerms.map(term => term.toLowerCase()).join(" "); const organizationName = organization.name.toLowerCase(); const searchString = `${searchTerms} ${organizationName}`; return searchString.includes(searchText.toLowerCase()); });