我尝试向已经成功运行的搜索栏添加另一个值 (organization.name),以便不仅过滤来自organization.topic 的SearchTerms 列表。但他没有添加它..
const filteredOrganizations = context.allOrganizations.filter((organization) => (organization.topic.searchTerms .map((term) => term.toLowerCase()) .join(" ") || organization.name) .includes(searchText.toLowerCase()))
这是我的退货的相关部分:
<TableBody> {filteredOrganizations.map((organization) => ( <StyledTableRow key={organization.id}> ...
希望你有想法
P粉7454121162023-09-08 11:29:47
不要使用||
,因为您还想检查组织名称。
只需连接字符串即可
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
这就是解决方案:
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()); });