【发布时间】:2018-12-18 02:53:27
【问题描述】:
我目前正在尝试创建一个类似于this one.的角色排名系统
使用官方 API,我可以通过 $.getJSON 和 URL 将所有数据附加到表格中。
到目前为止,我显示了 20 个字符并在多个表行中获取了所有字符数据(每个字符一个),但还没有弄清楚如何将字符对象拆分为多个 <td>,这样我可以更好地控制通过 CSS 解决它们。
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$.getJSON("http://api.pathofexile.com/ladders/Standard?callback=?", function (result) {
$("#tdPlayer").append("<td>" + result["total"] + "</td>" + "<br/>");
$("#tdSince").append("<td>" + result["cached_since"] + "</td>" + "<br/>");
$.each(result["entries"], function (index, value) {
$("#tdRanking").append("<tr>" + "<td>" + JSON.stringify(index, null, '\t') + ": " + JSON.stringify(value, null, '\t') + "</td>" + "</tr>" + "<br/>");
});
});
});
});
</script>
</head>
<body>
<button>Anzeige der Top 20 Spieler in der Incursion Liga</button>
<div>
<table>
<tr>
<td id="tdPlayer">Anzahl der Spieler:</td>
<td id="tdSince">Suchbeginn: </td>
</tr>
<tr>
<td colspan="2" id="tdRanking">Spieler: (max. 20 angezeigt)</td>
</tr>
</table>
</div>
</body>
</html>
我从 can be found here 附加我的数据的整个 JSON 对象。
【问题讨论】:
-
我们需要查看 JSON
-
我添加了一张带有对象的表格的屏幕截图。您可以看到我通过 api.pathofexile.com/ladders/Standard 附加的整个 JSON 对象
标签: javascript jquery html-table append getjson