有一段代码
<ul className="product-tags-list">
{
_(issueDisplayOrders).map((severity, index) =>
<li key={index}>
{issueCounts[severity]} {severity}
</li>
)
}
</ul>
issueDisplayOrders
就像
const issueDisplayOrders = ['Critical', 'Error', 'Warning', 'Information'];
和issueCounts
就像
issueCounts: PropTypes.shape({
Critical: PropTypes.number.isRequired,
Error: PropTypes.number.isRequired,
Warning: PropTypes.number.isRequired,
Information: PropTypes.number.isRequired
})
然而ul
被渲染为空
<ul class="product-tags-list"></ul>
根据我的单元测试。知道为什么吗?我猜我在某个地方犯了一些菜鸟错误。
答案 0 :(得分:0)
如果您没有使用lodash,地图将是这样的:
{
issueDisplayOrders.map((severity, index) => (
<li key={index}>
{`${issueCounts[severity]}${severity}`}
</li>
));
}
如果你正在使用lodash,那么:
{
_.map(this.props.selectedResponse, (severity, index) => (
<li key={index}>
{`${issueCounts[severity]}${severity}`}
</li>
));
}