我对 map 和 filter 功能有点困惑,请帮我解决我的问题。
这是我的代码。我只想突出显示选定的行。但是现在,当我选择一行时,整行都会突出显示。
{DocumentList && DocumentList.map(Doc =>
<tr key={Doc.DocID} className={selectedDocumentsForAttach.length !==0 && selectedDocumentsForAttach.filter(o => (o.DocID === Doc.DocID))?"print-table-row_hyLight":'print-table-row'}>
最佳答案
您的三元条件应评估为 bool 值。您应该使用 .some 而不是 .filter,如果您的参数函数调用中至少有一个返回 true,则返回 true。 Cf. MDN
关于css - 映射和过滤困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58092660/