Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从jQuery DataTable将行数据获取到数组中时出现问题_Javascript_Jquery_Datatables - Fatal编程技术网

Javascript 从jQuery DataTable将行数据获取到数组中时出现问题

Javascript 从jQuery DataTable将行数据获取到数组中时出现问题,javascript,jquery,datatables,Javascript,Jquery,Datatables,请查看并告诉我为什么无法将所选行放入数组中? 他的代码是我用来获取数据的代码: $(document).ready(function () { var arrLoadDb = []; $('#example').DataTable(); $('.add-row-db').on('click', function (e) { var $this = $(this); $this.closest('tr').find('td:not(td:

请查看并告诉我为什么无法将所选行放入数组中? 他的代码是我用来获取数据的代码:

$(document).ready(function () {
    var arrLoadDb = [];

    $('#example').DataTable();

    $('.add-row-db').on('click', function (e) {
        var $this = $(this);
        $this.closest('tr').find('td:not(td:first, td:last)').each(function () {
            arrLoadDb.push($(this).text());
            console.log(arrLoadDb);
        });
    });
});
但我得到的是这个结果,而不是数组

看看这个

每次单击按钮时,它都会搜索除fist和last列之外的所有列值


对于每按一次按钮,我们需要清除数组

,结果是一个数组。您的
arrLoadDb
变量是一个数组。您只需在循环外键入并获得预期的输出。另一个可能的基本错误是,每次单击都会将
arrLoadDb
添加到,但从未清除,这看起来是错误的
$(document).ready(function() {
    var arrLoadDb = [];

    $('#example').DataTable();

   $('.add-row-db').on('click', function(e){
    var $this = $(this);
       arrLoadDb = []
    $this.closest('tr').find('td:not(td:first, td:last)').each(function(){
    arrLoadDb.push($(this).text());

   });
       console.log(arrLoadDb);
  });


} );