How to use search bar with two different values?
P粉238433862
P粉238433862 2023-09-07 17:28:41
0
2
398

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粉238433862
P粉238433862

reply all(2)
P粉745412116

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粉083785014

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());
    });
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!