-2

I want to print a boolean value from JSON into a table, if I access directly to the status field, an empty value is displayed here is an example of json file:


    {
                'name':'client'
                'status':true,
                'method':'masterCard',
                'amount':'1700',

                }

jsx file :


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

          }]
OAH
  • 1,160
  • 2
  • 11
  • 24
  • 1
    what is your expection ouput – Hien Nguyen May 02 '19 at 15:32
  • nothing displayed – OAH May 02 '19 at 15:33
  • do you want convert from second JSON to first JSON? – Hien Nguyen May 02 '19 at 15:34
  • Please learn [the difference between JSON and Object Literal Notation](https://stackoverflow.com/questions/2904131/what-is-the-difference-between-json-and-object-literal-notation). – str May 02 '19 at 15:34
  • Possible duplicate of [How can I access and process nested objects and arrays?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-and-arrays) – str May 02 '19 at 15:49
  • I'm going to guess you could give in a template for your columns. Could you add which library you are using for displaying your table? You mention something about jsontable? – Icepickle May 03 '19 at 08:12
  • @HienNguyen He doesn't want to convert as far as I see, he just shows one row in the first one, and in the second the columns on how they will look? – Icepickle May 03 '19 at 08:13
  • I'm sorry for that , but i just identify my error – OAH May 03 '19 at 08:16

1 Answers1

1

The solution i found is to do a condition (is true or 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%",

      }]
OAH
  • 1,160
  • 2
  • 11
  • 24