0
我想從我的數據集中獲取json對象的名稱(本例中爲bdev0
和bdev1
)。如何獲取json對象的角度名稱
到目前爲止,我已嘗試ng-options沒有成功。我在下面的代碼中試圖實現的只是檢索json對象的名稱。到目前爲止,我所嘗試過的所有例子都不適用於我的案例。
代碼:
var myApp = angular.module('myApp', []);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.data = [{
"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
}]
}
HTML
<div ng-controller="MyCtrl">
<select name="Block_Devices" ng-model="selectedDevice" ng-options="value.Block_Devices for value in data">
<option value="">Please Select Device</option>
</select>
</div>
Selected Device = {{selectedDevice}}
NG選項=」數據[0]中的(鍵,值)鍵.Block_Devices「將在select中工作 – Nils