javascript - 我如何在表中以 JSON 格式打印布尔值
问题描述
我想将 JSON 中的布尔值打印到表中,如果我直接访问状态字段,则会显示一个空值,这里是 json 文件的示例:
{
'name':'client'
'status':true,
'method':'masterCard',
'amount':'1700',
}
.jsx 文件:
const columns = [
{
title: "name",
dataIndex: "name",
key: "name",
width: "20%"
},
{
title: "status",
dataIndex: "status",
key: "status",
width: "20%"
},
{title: "Method Paiment",
dataIndex: "method",
key: "method",
width: "20%",
}]
解决方案
我找到的解决方案是做一个条件(是 true 或 false ):
const columns = [
{
title: "name",
dataIndex: "name",
key: "name",
width: "20%"
},
{
title: "status",
dataIndex: "status",
key: "status",
width: "20%",
render: statut => {
if (statut == true) {
return (
<Tag color="#1890ff" key={statut}>
Is True
</Tag>
);
}
return (
<Tag color="#d48806" key={statut}>
Is False
</Tag>
);
}
},
{title: "Method Paiment",
dataIndex: "method",
key: "method",
width: "20%",
}]
推荐阅读
- php - org.json.JSONObject:值
我正在尝试将数据插入远程 mysql 数据库。我遇到的问题是解析位于远程服务器中的 php 文件。我总是得到这个 java.lang.String 类型的值 php 无法转换为 JSONObject 的错误。
这是我的php代码:
&
- python - 如何从搜索对象中检索第二个值?
- javascript - Firebase 云函数和异步/等待
- wpf - 如何使绑定的网格大小成为比例值?
- node.js - 调用注册端点失败并出现错误 [错误:自签名证书]
- c++ - (如何)我可以矢量化`std::complex
` 使用openmp? - c++ - 以找到的库为条件的编译
- javascript - 我可以在 application+json 脚本中做数学吗?
- java - Kotlin 中 getOrElseReturn 的可能性
- excel - 匹配子串并计算它们的出现次数以产生一个简短的句子