gpt4 book ai didi

javascript - 通过 rest api 调用数据不知道如何调用表中的数据

转载 作者:行者123 更新时间:2023-11-29 23:25:19 24 4
gpt4 key购买 nike

想调用表中md中的所有数据我尝试了所有可能的值,但没有解决,所以指导我如何使用 md 值在表中显示

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$.get("https://cricapi.com/api/matches?apikey==apikey", function(matchdata) {
console.log(matchdata.matches);
matchdata.matches.forEach(function(md) {
console.log(md.description + " - to grab more details, simply use the unique_id " + md.unique_id + " with the cricketScore api!");

return true;

});
});
</script>

最佳答案

var $tableBody = $('#tableBody');

function createRow(dm) {
var team_1 = dm['team-1'],
team_2 = dm['team-2'],
winner = (
dm['toss_winner_team'] ?
dm['toss_winner_team'] :
'N/A'
)
return (
'<tr>' +
'<td>' + team_1 + '</td>' +
'<td>' + team_2 + '</td>' +
'<td>' + winner + '</td>' +
'</tr>'
)
}
$.get("https://cricapi.com/api/matches?apikey=your key", function(matchdata) {
console.log(matchdata.matches);
var rows = matchdata.matches.map(createRow).join('');

$tableBody.html(rows);
});
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>

<body>
<table>
<thead>
<tr>
<td>Team A</td>
<td>Team B</td>
<td>Winner</td>
</tr>
</thead>
<tbody id="tableBody">
<tbody>
</table>
</body>

</html>

DEMO

关于javascript - 通过 rest api 调用数据不知道如何调用表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49524874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com