gpt4 book ai didi

javascript - 如何以 Angular 获取json对象的名称

转载 作者:行者123 更新时间:2023-12-02 14:39:15 25 4
gpt4 key购买 nike

我有一个数据集

$scope.mydata = [{
"Block_Devices": {
"bdev0": {
"Backend_Device_Path": "/dev/ram1",
"Capacity": "16777216",
"Bytes_Written": 1577,
"timestamp": "4365093970",
"IO_Operations": 17757,
"Guest_Device_Name": "vdb",
"Bytes_Read": 17793,
"Guest_IP_Address": "192.168.26.88"
},
"bdev1": {
"Backend_Device_Path": "/dev/ram2",
"Capacity": "16777216",
"Bytes_Written": 1975,
"timestamp": "9365093970",
"IO_Operations": 21380,
"Guest_Device_Name": "vdb",
"Bytes_Read": 20424,
"Guest_IP_Address": "192.168.26.100"
}
},
"Number of Devices": 2
}]

我想从这个 json 创建一个数组,例如

devices = ['bdev0', 'bdev1']

当我尝试

$scope.mydata.Block_Devices 它给了我整个 json 对象,但我只想要对象的名称,即 bdev0 和 bdev1 我怎样才能得到它?

最佳答案

试试这个:

var devices = [];

for (var key in $scope.mydata[0].Block_Devices) {
devices.push(key)
}

关于javascript - 如何以 Angular 获取json对象的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37160128/

25 4 0
文章推荐: javascript - 当表中有