简体   繁体   中英

Nested JSON with dynamic Key Values in LWC

I have a JSON Data and I would like to iterate on runStatus , however not all the nodes have runStatus and I am getting error that run.runStatus is Undefined .

How can i fix the error in HTML?

[
    {
        "Code": "AB",
        "Run": {
            "Range": {
                "maxValue": "75",
                "minValue": "54"
            },
            "remarks": [],
            "runStatus": "RESULTED"
        }
    },
    {
        "Code": "CD",
        "Run": {
            "remarks": []
        }
    }
]

do a check before

if(YOUR_OBJ.Run.runStatus !== undefined)
{
  console.log(YOUR_OBJ.Run.runStatus);
  // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM