要求
將圖一格式數據轉化成圖二格式數據
原始json數據
[{
"id": 15,
"paramName": "distance",
"paramValue": "1",
"description": "定位前後位置在一定距離內不跳動 單位:米",
"companyId": 1,
"paramTypeId": 2
}, {
"id": 110,
"paramName": "floorNum",
"paramValue": "centerIndex",
"description": "樓層編號",
"companyId": 1,
"paramTypeId": 2
}, {
"id": 119,
"paramName": "gltfFloor",
"paramValue": "1",
"description": "gltf樓層",
"companyId": 1,
"paramTypeId": 2
},{
"id": 94,
"paramName": "imageryProvider",
"paramValue": "0",
"description": "0:無室外圖;1:矢量室外圖;2:影像圖",
"companyId": 1,
"paramTypeId": 2
} , {
"id": 113,
"paramName": "TwoDim",
"paramValue": "2",
"description": "2D地圖,1矢量圖 2切片圖",
"companyId": 1,
"paramTypeId": 2
}]
轉換代碼
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>複選框checkbox自定義樣式</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="modal-body form">
</div>
</body>
<script type="text/javascript">
$.ajax({
url: "test.json",
type: 'GET',
dataType: 'json',
success: function(data) {
const obj = {}
data.forEach(a => {
obj[a.paramName] = a
})
console.log(obj)//你要的對象
}
});
</script>
</html>
查看結果