I have got json data in a file (/static/models.json) like this in angular JS project ..
{
"familyType": {
"A650": [{
"partID": "2630_H"
}, {
"partID": "2690_H"
}, {
"partID": "2680_H"
}, {
"partID": "2600_H"
}, {
"partID": "2620_H"
}, {
"partID": "2610_H"
}],
"S400": [{
"partID": "S500_Aru"
}, {
"partID": "S600_Aru"
}, {
"partID": "S700_Aru"
}, {
"partID": "S800_Aru"
}, {
"partID": "S900_Aru"
}, {
"partID": "S100_Aru"
}
]
}
}
I have got below function with parameters passing into that method (Part_id1, Part_id2) and inside the function..I have got two family types (A650,S400) and i need to check whether the two input part_Id's(Part_id1, Part_id2) are belongs to same family or not (i.e either A650 or S400 )
If the two part_id's(Part_id1, Part_id2) are from different family types i need to alert user ... how can we traverse through json file and compare the part_ID's in both the family types ..
$scope.ValidateModelList = function(Part_id1, Part_id2, $http) {
if ($scope.firTable.selectedRowsCount != 0) {
$http.get("/static/models.json")
.success(function(response) {
$scope.names = response;
});
// here i am storing json data in $scope.names object
// here i need to check that the part_ids with the family
}
}
Would any one please help on this that would be very grateful to me....
Many thanks in advance ....
Update
function ValidateModel(partIDlist){
alert('2');
var data = stubdata; // Stubdata is actual json data mentioned above
var partIdResult = [];
for (var key in data.familyType) {
angular.forEach(data.familyType[key], function (object) {
angular.forEach(partIDlist, function (partId) {
if (partId == object.partID) {
partIdResult.push({
value: partId, family: key
});
}
});
});
}
for (var i = 0; i < partIdResult.length; i++) {
// alert(partIdResult.length);
//alert(partIdResult.family);
alert(JSON.stringify(partIdResult))
alert(partIdResult.family); // this is giving undefined value
alert(partIdResult[0].family);
if (partIdResult.family === partIdResult[0].family){
alert('yes');
alert("part_id's are same");
}
else if (partIdResult.family !== partIdResult[0].family) {
alert("part_id's not same");
}
}
}
here I am passing a list like this ..
var partIDlist= ["S900_Aru", "S500_Aru", "2610_H"];
and I am getting alert(JSON.stringify(partIdResult)) partIdResult as like this
[{"value":"S900_Aru","family":"S400"},
{"value":"S500_Aru","family":"S400"},
{"value":"2610_H","family":"A650"}]
I should get these three part_id's are not belong to same model .. instead of this I am getting part_id's are belongs to same
could you please help on this ... Many thanks in advance....