【发布时间】:2026-01-22 14:15:01
【问题描述】:
我正在构建一个程序来打印 OpenSky 网络 api 信息。飞机信息数组的api返回数组。我想知道如何将飞机信息打印到 html 表中。看到它返回一个数组数组。我正在尝试将第二个数组中的信息打印到表格中。
此刻的代码将数组打印到列。
控制台日志:Console image return from api
当前结果:enter image description here HTML:
<html>
<head>
<title>Data</title>
<link rel='stylesheet' href='/stylesheets/header.css' />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script rel="script" src='/javascripts/displayData.js'></script>
</head>
<body>
<%include templates/header.ejs%>
<table id="data">
<tr>
<th>ICAO24</th>
<th>CountryOrigin</th>
<th>longitude</th>
<th>latitude</th>
<th>altitude</th>
<th>velocity m/s</th>
</tr>
</table>
</body>
</html>
JS:
const api_url = 'https://opensky-network.org/api/states/all?lamin=45.8389&lomin=5.9962&lamax=47.8229&lomax=10.5226';
$(document).ready(function () {
$.get(api_url, function (data,status) {
console.log(data.states);
var states = (data.states);
$.each(states, function () {
$("#data").append('<tr><td>' + states[0] + '</td><td>' + data.states[2] + '</td><td>' + data.states[5] + '</td><td>' + data.states[6] + '</td><td>' + data.states[7] + '</td><td>' + data.states[9] + '</td></tr>')
})
})
}) ```
【问题讨论】:
标签: javascript jquery html arrays