【发布时间】:2020-12-05 20:17:22
【问题描述】:
假设在 React 中,我正在迭代返回状态为 this.state.searchData 的 JSON 数据,并且返回的一些值包含来自 api 调用的 true 或 false 或 null,例如:
"active": true,
"partition": null,
"auth": false
对于下面的地图迭代,我将如何测试键/值中的每个值,然后用字符串“true”或“false”或“null”替换它们以显示在浏览器的渲染中?现在我的代码正确呈现所有内容,直到它在键的值中遇到真、假或空,它只呈现任何内容/空
{Object.entries(this.state.searchData).map(([key, value]) => (
<ul>
*** test key value here for null, false or true and output string "null, false or true"
<li>{key} : {value}</li>
</ul>
)
)
}
【问题讨论】:
标签: javascript node.js reactjs ecmascript-6