I have a JSON Array similar to the structure below.
[{
"variable_name": "VAR1_XYZ",
"variable_values": [
{
"DomainName": "Env1",
"Value": "ABC Process 1",
(some more key-value pairs)
},
{
"DomainName": "Env2",
"Value": "DEF Process 1",
(some more key-value pairs)
}],
},{
"variable_name": "VAR2_UVW",
"variable_values": [
{
"DomainName": "Env1",
"Value": "ABC Process 2",
(some more key-value pairs)
},
{
"DomainName": "Env2",
"Value": "DEF Process 2",
(some more key-value pairs)
}],
}];
I am presenting this data in a table structure with the "variable_name" (as rows / cells) value's across multiple "DomainName"s (as columns) in an "ng-grid".
I am also having a requirement where the user up on selecting one of the "DomainName"s, the values of the "variable_name"s in the selected Domain would have to be compared against the values with the other Domains and depending on whether there is a match or not, the "ng-grid" table cells need to be color coded as "green" or "red" depending on whether there is a match or not..
I had been looking through plain javascript / json object manipulation and underscore / lodash to understand which is the most efficient way to compare JSON objects with the following structures and I could not come to any conclusion on how to achieve it. I am also a newbie to the lodash / underscore library and may be that is causing this confusion if I am over engineering or if I am taking the right path to solve this problem.
My end goal is to create a generic function that takes the selected domain name and the below array to provide an output array that has a list of true / false boolean values for each "variable_name" / "DomainName" that I can use for coloring the grid.
So, for example, if the user selects DomainName as "Env1", I am looking to get all "variable_name"'s under "Env1" and compare the values of the respective "variable_name"s from other domains and create a result object similar to
{Env1 : true, Env2: false, Env3 : true}
that I can use for coloring the ng-grid. Could you please suggest on what is the approach that should be taken if this has to be done using lodash / underscore? instead of plain javascript?