【问题标题】:how can i print a boolean value in JSON in table我如何在表中以 JSON 格式打印布尔值
【发布时间】:2019-05-02 15:29:32
【问题描述】:

我想将 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%",

          }]

【问题讨论】:

标签: javascript json reactjs


【解决方案1】:

我找到的解决方案是做一个条件(是真还是假):

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%",

      }]

【讨论】:

    猜你喜欢
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多