当我从datatable jquery获取所有数据时,我遇到了一些问题,而不是我想要的数组.Below是我的代码,
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函数。所以它是任何可能的方式。任何帮助都会非常感激。谢谢你
答案 0 :(得分:1)
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);