我怎样才能调用数据表js'只有一次?

时间:2018-04-02 07:29:23

标签: javascript ajax datatables

我有多个用数据表js创建的表。问题是,当我单击一个选项卡时,加载数据表的函数被调用两次,我无法理解为什么。

以下是带标签的表格如何:   

以下是我使用的代码:

function deletedTesters() {
if (typeof table3 == 'undefined') {
    table3 = $('#testers-table3').dataTable({
        'processing': true,
        'serverSide': true,
        'deferRender': true,
        'autoWidth': false,
        'ajax': {
            'dataType': 'json',
            'type': 'POST',
            'draw': 1,
            'async': true,
            'url': '<?php echo site_url('ajax/testers_list');?>',
            'data': function ( d ) {
                d.advanced_search = $('table.advanced_search').parents('form').serialize().replace(/\&/g,'++++');
            },
            'cache': true
        },
        'aaSorting': [[ <?php echo !empty($testers_deleted_filters['order'][0]['column'])?$testers_deleted_filters['order'][0]['column']:1;?>, '<?php echo !empty($testers_deleted_filters['order'][0]['dir'])?$testers_deleted_filters['order'][0]['dir']:'desc';?>' ]],
        'pagingType': 'full_numbers',
        'pageLength': <?php echo !empty($testers_deleted_filters['length'])?$testers_deleted_filters['length']:25;?>,
        'displayStart': <?php echo !empty($testers_deleted_filters['start'])?$testers_deleted_filters['start']:0;?>,
        'aLengthMenu': [ 10, 25, 50, 100,250 ],
        'search': {'search': '<?php echo !empty($testers_deleted_filters['search']['value'])?$testers_deleted_filters['search']['value']:'';?>'},
        'aoColumns': [
            {'bSearchable': false, 'bSortable': false},
            null,
            null,
            null,
            {'bSearchable': false},
            {'bSearchable': false},
            {'bSearchable': false},
            {'bSearchable': false},
            {'bSearchable': false},
            {'bSearchable': false, 'bSortable': false}
        ],
        drawCallback: function() { init_tooltips('#testers-table3'); }
    });
  }
} 

$('#tabs').tabs({
selected: <?php echo $testers_list_tab;?>,
show: function(event, ui) {
    $('.section-panel h2:eq(0)').text($('li.ui-tabs-selected a').text());
    if ($('#tabs ul.idTabs').find('li:last-child').hasClass('ui-state-active')) {
        $('.bulk-ops').hide();

    } else {
        $('.bulk-ops').show();
    }
    switch(ui.index){
        case 2:{
            deletedTesters();
            $('.btn-anonymise').show();
            $('.btn-delete').hide();
            break;
        }

    }
  }
});

0 个答案:

没有答案