【发布时间】:2022-01-14 13:01:23
【问题描述】:
如何在表格行中使用 postRes 实现这两个过滤器? postRes 是 json api 响应。 includeKeyword & searchVolume 是状态钩子。如果状态为空,我不想实现过滤器。提前感谢您的帮助
let includeKeywordResults = !includeKeyword ? postRes : postRes.filter(data =>
data.text.toLowerCase().includes(includeKeyword.toLocaleLowerCase()))
let searchVolumeResults = !searchVolume ? postRes : postRes.filter(data =>
data.keyword_idea_metrics.avg_monthly_searches > parseInt(searchVolume) )
返回
<div className="container table-responsive py-5">
<table className="table table-bordered table-hover" id="table-to-xls">
<thead className="text-white bg-dark">
<tr>
<th scope="col">Keyword</th>
<th scope="col">Search Volume</th>
<th scope="col">Competition</th>
<th scope="col">CPC</th>
</tr>
</thead>
<tbody>
{includeKeywordResults !== undefined ? includeKeywordResults.map((data, index) => (
<tr key={index}>
<td>{data.text}</td>
<td>{data.keyword_idea_metrics.avg_monthly_searches}</td>
<td>{data.keyword_idea_metrics.competition}</td>
<td>{data.keyword_idea_metrics.low_top_of_page_bid_micros}</td>
</tr>
)) : null}
</tbody>
</table>
</div>
</div>
}
【问题讨论】:
标签: javascript arrays reactjs react-hooks