Summary :
There are three dropdowns for each levelNum. such as dropdown for levelNum2 contains (Department-Unit-1, Department-Unit-2 & Department-Unit-3),levelNum3 contains (Division-Unit-1 & Division-Unit-2) and levelNum4 contains (Business-Unit-1 & Business-Unit-2).
There is an array of objects.Inside each object there is a property named hierarchyLevels which is again an array of objects.Inside each object there is a two property unitName & levelNum as shown in below JSON.
var data = [{
"hierarchyLevels": [{
"unitName": "Department-Unit-3",
"levelNum": 2
}, {
"unitName": "Division-Unit-2",
"levelNum": 3
}, {
"unitName": "Business-Unit-1",
"levelNum": 4
}]
}, {
"hierarchyLevels": [{
"unitName": "Department-Unit-1",
"levelNum": 2
}, {
"unitName": "Division-Unit-1",
"levelNum": 3
}, {
"unitName": "Business-Unit-2",
"levelNum": 4
}]
}, {
"hierarchyLevels": [{
"unitName": "Department-Unit-2",
"levelNum": 2
}, {
"unitName": "Business-Unit-1",
"levelNum": 4
}]
}]
Tried so far :
function getMultipleObjectFromList(propertyName, value, list){
return list.filter(function (item) {
return item.hierarchyLevels.some(function (level) {
return level[propertyName] === value;
});
});
};
var res = getMultipleObjectFromList('unitName','Business-Unit-1',data);
Requirement :
I want to fetch all unitName associated with another unitName. So, if I select Business-Unit-1 from the levelNum4 dropdown, the other low level dropdown will auto fill with unitName associated with Business-Unit-1.i.e levelNum3 dropdown will contain only Division-Unit-2 and levelNum2 dropdown will contain (Department-Unit-2 & Department-Unit-3).
tried so farsection.if(tempObj[propertyName] == value)withif(tempObj.hierarchyLevels[propertyName] === value)solves your problem? In case it does not help, can you post how the result of your function should look like? What structure should the resulting object have?"the other low level dropdown"you mean dropdowns withlevelNumless than the selected one? 2. How do you determine the association between two or moreunitName?