【发布时间】:2020-02-26 18:27:51
【问题描述】:
在这里,我有 10 个 Json 对象。我正在尝试使用overflow:auto 在桌子上添加一个滚动条但这里有一个转折,我真正想要的是我的滚动条触到底部的那一刻,我想设置一个条件,比如上面的 10 个值再次重复,但是仅当滚动条到达底部并且我希望它处于无限循环中时。
到目前为止我做了什么 这里我将 JSON 对象放入数组中。
var response = [
{
"CategoryName":"Beverages",
"ProductName":"Steeleye Stout"
},
{
"CategoryName":"Beverages",
"ProductName":"Laughing Lumberjack Lager"
},
{
"CategoryName":"Beverages",
"ProductName":"Lakkalik\u00f6\u00f6ri"
},
{
"CategoryName":"Beverages",
"ProductName":"Guaran\u00e1 Fant\u00e1stica"
},
{
"CategoryName":"Beverages",
"ProductName":"Ipoh Coffee"
},
{
"CategoryName":"Beverages",
"ProductName":"Chang"
},
{
"CategoryName":"Beverages",
"ProductName":"Chartreuse verte"
},
{
"CategoryName":"Beverages",
"ProductName":"Ipoh Coffee"
},
{
"CategoryName":"Beverages",
"ProductName":"Chai"
},
{
"CategoryName":"Beverages",
"ProductName":"Chang"
}
]
现在我创建了 i 表,但我也想对其进行更改,我只想要 5 个条目。接下来的五个,我想从滚动条访问。
var key = [];
document.write("<table border==\"1\"><tr>");
for (key in response[0]) {
document.write('<td>' + '<b>' + key + '</b>' + '</td>');
}
document.write("</tr>");
for (var i = 0; i < response.length; i++) {
document.write('<tr>');
for (key in response[i]) {
document.write('<td>' + response[i][key] + '</td>');
}
document.write('</tr>');
}
document.write("</table>");
我希望你们明白我想问什么。在此先感谢:)
【问题讨论】:
-
我想这个链接会对你有所帮助。 stackoverflow.com/a/21561584/3664161
标签: javascript json html-table conditional-statements