-
Notifications
You must be signed in to change notification settings - Fork 0
/
排序.html
58 lines (43 loc) · 2.05 KB
/
排序.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="section"></div>
<script>
var weatherData;
var url = 'https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-C0032-001?Authorization=CWB-02A7A1BA-2820-406F-82DE-E63232A7999B&format=JSON';
var cities = ['新北市', '臺北市', '基隆市', '桃園市', '新竹縣', '新竹市', '苗栗縣', '臺中市', '彰化縣', '南投縣', '雲林縣', '嘉義縣', '嘉義市', '臺南市', '高雄市', '屏東縣', '宜蘭縣', '花蓮縣', '台東縣', '澎湖縣', '金門縣', '連江縣'];
var orgData = {};
fetch(url)
.then(function (response) {
return response.json();
})
.then(function (result) {
var locations = result['records']['location'];
locations.forEach((location) => {
var locationName = location["locationName"];
var wx = location["weatherElement"][0]["time"][0]["parameter"]["parameterName"];
var startTime = location["weatherElement"][0]["time"][0]["startTime"];
var endTime = location["weatherElement"][0]["time"][0]["endTime"];
orgData[locationName] = {
"startTime": startTime,
"endTime": endTime,
"wx": wx,
};
});
console.log(orgData);
var section = document.querySelector('.section');
section.innerHTML = "";
cities.forEach((city) => {
console.log(city);
section.innerHTML +=`<div>${city} -${orgData[city]['startTime']} - ${orgData[city]['endTime']} - ${orgData[city]["wx"]} </div>`;
})
});
</script>
</body>
</html>