Below is my json structure:
$scope.dataList = [{
CompanyName: null,
Location: null,
Client: {
ClientId: 0,
ClientName: null,
Projects:{
Id: 0,
Name: null,
}
}
}];
I have this data in dataList scope variable :
[{
CompanyName: XXXX,
Location: California,
Client:{
ClientId: 1,
ClientName: John Cena,
Projects:{
Id: 1,
Name: Abc,
}
}
}]
Now in the above record I need to find by company name and location and add Client array to matched company.
Now based on button click event i am getting 1 or more another record from http call like below:
[{
CompanyName: XXXX,
Location: California,
Client:[{
ClientId: 2,
ClientName: Undertaker,
Projects:{
Id: 2,
Name: Pqr,
}
}]
}]
Now i want to append this new client data to my dataList object for company XXXX and for location California.
This is how i am trying but I am getting errors:
$http.get("Url")
.then(function(data) {
for (var i = 0; i < data.length; i++) // when there will be more than 1 records in response i get from http call
{
var result = $.grep($scope.dataList, function (e)
{
//find records from dataList by Company name and Location
return (e.CompanyName == data[i].CompanyName) && (e.Location == data[i].Location);
});
//Push client Id 2 record in dataList
result.Client.push(data[i]);// error:result.Client is undefined
console.log(result);
}
});
Can anybody please help me with this??