[英]javascript - split array into multiple page index
I have a function called Render(arr). 我有一个称为Render(arr)的函数。 Arr is a parameter that contain 50 rows of data. Arr是包含50行数据的参数。 I have an empty div in html page 我在html页面中有一个空的div
<div id="test"></div>
when I use this javascript code 当我使用此javascript代码时
var s=""
for(i<0;i<arr.length;i++{
s+= arr[i].attr1.toString();
s+= arr[i].attr2.toString();
s+= arr[i].attr3.toString();
}
var data = document.getElementById("test");
data.innerHTML = s;
It will render all the 50 rows of data along with the attributes in a html page which is space-consuming. 它将呈现所有50行数据以及html页面中的属性,这会占用大量空间。 How to make page indexing if i want to split the array into page indexing that a page only contain 5 data? 如果我想将数组拆分成一个页面仅包含5个数据的页面索引,如何进行页面索引? eg page 1 only show data row 1-5, page 2 only show data row 6-10 without refreshing the page? 例如,第1页仅显示数据行1-5,第2页仅显示数据行6-10,而不刷新页面?
thanks 谢谢
var page = curr_page - 1;
for(i=page*5;i<page*5+5;i++{
s+= arr[i].attr1.toString();
s+= arr[i].attr2.toString();
s+= arr[i].attr3.toString();
}
Something like this? 像这样吗
if curr_page = 1 the for will loop 5 times, from 0 to 5 如果curr_page = 1,则for循环5次,从0到5
if its 2 it will loop from 5 to 10 and so on. 如果其值为2,则会从5循环到10,依此类推。
for(var i = current_page * 5 - 5, j = 0; j < 5; j++, i++) {
s += arr[i].attr1.toString();
s += arr[i].attr1.toString();
s += arr[i].attr1.toString();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.