I've scoured the internet for solutions to a similar issue but haven't been able to find any helpful information yet.
My current challenge involves accessing a picture path (in JSON format) based on the material type of the selected element. Here is how my code currently looks:
if (globalData.Material.Mat_type == "OSCILLOSCOPE") {
var picture = (globalData.Material.Oscilloscope.picture);
}
if (globalData.Material.Mat_type == "ALIMENTATION") {
var picture = (globalData.Material.Alim.picture);
}
This setup isn't optimized, so I'm attempting to refactor it like this:
var mat_type = (globalData.Material.Mat_type);
var picture = (globalData.Material[mat_type].picture);
Unfortunately, this strategy doesn't seem to be working as intended. An exception has been thrown:
TypeError : globalData.Material[mat_type] is undefined.
I've experimented with various approaches already. Do you have any insights or ideas? Thank you!