Javascript 如何在表中打印JSON中的布尔值
我想将JSON中的布尔值打印到一个表中,如果我直接访问status字段,将显示一个空值 以下是json文件的一个示例:Javascript 如何在表中打印JSON中的布尔值,javascript,json,reactjs,Javascript,Json,Reactjs,我想将JSON中的布尔值打印到一个表中,如果我直接访问status字段,将显示一个空值 以下是json文件的一个示例: { 'name':'client' 'status':true, 'method':'masterCard', 'amount':'1700', } jsx文件: const columns =
{
'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%",
}]
我找到的解决方案是做一个条件(是真是假):
const列=[
{
标题:“姓名”,
数据索引:“名称”,
键:“名称”,
宽度:“20%”
},
{
标题:“地位”,
数据索引:“状态”,
密钥:“状态”,
宽度:“20%”,
呈现:statut=>{
如果(statut==true){
返回(
是真的
);
}
返回(
是假的
);
}
},
{标题:“方法付款”,
数据索引:“方法”,
键:“方法”,
宽度:“20%”,
}]
您的预期输出是什么?未显示任何内容您是否希望从第二个JSON转换为第一个JSON?请了解。可能存在重复的
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%",
}]