Issue
I have two tables with keys and values, but the keys are not in order. I need to compare the values of the matching keys between the tables and highlight the background if they are different. My code is not working, and I need help to fix it.
Resolution
The solution involves using a ternary operator in order to display different text values based on the boolean value. In this case, the ternary operator checks whether the boolean value is true or false and displays "natural" or "synth" accordingly.
For example: {{currentRow.Nat == "true" ? "natural" : "synth"}}
In order to compare two tables with different orders of keys and highlight the background if the corresponding values differ, you can use an if statement within a function. The function checks if the key exists in the first table, retrieves its corresponding value, and compares it with the value in the second table. If they differ, the background is highlighted in red.
Example code:
{{(function(){
if(Object.hasOwn(api1.data.object1, currentRow.Brandkey)){
const val1 = api1.data.object1[currentRow.Brandkey];
if(currentRow.Value !== val1) {
return 'background-color: red';
}
}
return 'background-color: transparent';
})()}}