为什么这些列表项不呈现?

时间:2017-07-24 20:22:52

标签: javascript html reactjs jsx

有一段代码

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

根据我的单元测试。知道为什么吗?我猜我在某个地方犯了一些菜鸟错误。

1 个答案:

答案 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>
  ));
}