gpt4 book ai didi

javascript - 将数据管理到数据表中的数组

转载 作者:行者123 更新时间:2023-12-03 06:28:05 25 4
gpt4 key购买 nike

当我从数据表 jquery 获取所有数据时,我遇到了一些问题,它不在我想要的数组中。下面是我的代码,

var cells = [];
var rows = $("#PtptnFileTblId_1").dataTable().fnGetNodes();
for(var ii = 0; ii < rows.length;ii++)
{
for(var i = 1; i < 15 ;i++){
cells.push($(rows[ii]).find('td:eq('+ i +')').html());
}
}
console.log(cells);

当我看到控制台日志时,数据显示如下:

["0000000000", "BP4", "99", "00987799201502", "SB1302BD2613", "911224126057", "Test1", "00791740", "zxa", "000000", "00000000", "null", "null", "10016020876162", "0000000000", "BP4", "59", "01678059201502", "MC1411BC8301", "940627146418", "Test2", "00672980", "qwq", "000000", "00000000", "null", "null", "12131023048090", "0000000000", "BP4", "13", "01482513201502", "SB1409BD7872", "910120126189", "Test3", "00672894", "AU", "000000", "00000000", "null", "null", "10016020934832"]

但我想要的方式是,

[Array[15], Array[15], Array[15]
0:[Array[15]
0:"0000000000"
1:"BP4"
2:"99"
3:"00987799201502"
4:"SB1302BD2613"
5:"12121312"
6:"TEST1"
7:"00791740"
8:"zxa"
9:"000000"
10:"00000000"
11:"null"
12:"null"
13:"10016020876162"
2:[Array[15]
0:"0000000000"
1:"BP4"
2:"99"
3:"00987799201502"
4:"SB1302BD2613"
5:"12121312"
6:"TEST1"
7:"00791740"
8:"zxa"
9:"000000"
10:"00000000"
11:"null"
12:"null"
13:"10016020876162"
3:[Array[15]
0:"0000000000"
1:"BP4"
......

请任何人帮助我如何像上面显示的那样转换我的代码。这是我第一次使用像 .push() 这样的 jquery 函数。所以有没有可能的方法。任何帮助将不胜感激。谢谢

最佳答案

array.splice(0, 15) 每次都会从数组中获取 15 个元素。

var arr = ["0000000000", "BP4", "99", "00987799201502", "SB1302BD2613", "911224126057", "Test1", "00791740", "zxa", "000000", "00000000", "null", "null", "10016020876162", "0000000000", "BP4", "59", "01678059201502", "MC1411BC8301", "940627146418", "Test2", "00672980", "qwq", "000000", "00000000", "null", "null", "12131023048090", "0000000000", "BP4", "13", "01482513201502", "SB1409BD7872", "910120126189", "Test3", "00672894", "AU", "000000", "00000000", "null", "null", "10016020934832"]

var result = [];

while(arr.length) {
result.push(arr.splice(0,15));
}

console.log(result);

关于javascript - 将数据管理到数据表中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38557683/

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