首页 > 解决方案 > 我如何在表中以 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%",

          }]

标签: javascriptjsonreactjs

解决方案


我找到的解决方案是做一个条件(是 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%",

      }]

推荐阅读