I have a JSON structure that looks like this:
var myJson = {
"Number of Devices":2,
"Block Devices":{
"bdev0":{
"Backend_Device_Path":"/dev/ram1",
"Capacity":"16777216",
"Bytes_Written":9848,
"timestamp":"4365093970",
"IO_Operations":87204,
"Guest_Device_Name":"vdb",
"Bytes_Read":107619,
"Guest_IP_Address":"192.168.26.88"
},
"bdev1":{
"Backend_Device_Path":"/dev/ram2",
"Capacity":"16777216",
"Bytes_Written":10062,
"timestamp":"9365093970",
"IO_Operations":93789,
"Guest_Device_Name":"vdb",
"Bytes_Read":116524,
"Guest_IP_Address":"192.168.26.100"
}
}
}
I am attempting to extract the information for Block Devices labeled as bdev0, bdev1... along with their corresponding values. Typically, using Object.keys in vanilla JavaScript makes this task straightforward. However, it appears that I cannot utilize this function in Angular. Instead, I attempted to use angular.forEach, but encountered an issue resulting in 'undefined'.
Here is the progress I have made so far:
function getData(){
$http.get(path)
.success(function(data){
$scope.devices = data
angular.forEach($scope.devices, function(item){
console.log(item['Block Devices']);
})
})
}