Javascript 在通用功能中维护选中的列表复选框

Javascript 在通用功能中维护选中的列表复选框,javascript,jquery,checkbox,Javascript,Jquery,Checkbox,我的应用程序中有很多数据表。每个表都有一个复选框列,标题上有一个主复选框用于选中/取消选中全部 为了避免复制/粘贴处理选中/取消选中的代码,我在主应用程序中关闭了它 但是我需要为显示的页面保留选中复选框的状态,该页面有自己的js脚本 如何使这足够通用 这是一个示例,我在主应用程序中处理了更多的东西 var App = (function () { var handleDataTables = function () { var table; table =

我的应用程序中有很多数据表。每个表都有一个复选框列,标题上有一个主复选框用于选中/取消选中全部

为了避免复制/粘贴处理选中/取消选中的代码,我在主应用程序中关闭了它

但是我需要为显示的页面保留选中复选框的状态,该页面有自己的js脚本

如何使这足够通用

这是一个示例,我在主应用程序中处理了更多的东西

var App = (function () {
    var handleDataTables = function () {
        var table;
        table = $('.dataTable');
        table.aSelected = [];
        table.on('draw.dt', function (e, settings, json) {
            handleUniform();
        });
        table.on('xhr.dt', function (e, settings, json) {
            $(this).add('.group-checkable').change(function () {
                var set, group_checked;
                set = $(this).attr("data-set");
                group_checked = $(this).is(":checked");

                $(set).each(function () {
                    if (group_checked) {
                        $(this).prop('checked', true);
                        if ($.inArray($(this).attr("value"), table.aSelected) === -1) {
                            table.aSelected.push($(this).attr("value"));
                        }
                    } else {
                        $(this).prop('checked', false);
                        table.aSelected.pop($(this).attr("value"));
                    }
                });
                $.uniform.update(set);
            });

            $(this).add('.checkboxes').change(function (e) {
                var checked;
                checked = $(e.target).is(":checked");
                console.log(table.DataTable);
                if (checked) {
                    if (table.aSelected.length === table[0].rows && !$(this).add('.group-checkable').parent().hasClass("checked")) {
                        $(this).add('.group-checkable').parent().addClass('checked');
                    }
                    console.log($.inArray($(e.target).attr("value"), table.aSelected));
                    if ($.inArray($(e.target).attr("value"), table.aSelected) === -1) {
                        table.aSelected.push($(e.target).attr("value"));
                    }
                } else {
                    if ($(this).add('.group-checkable').parent().hasClass("checked")) {
                        $(this).add('.group-checkable').parent().removeClass('checked');
                    }
                    table.aSelected.pop($(e.target).attr("value"));
                }
                console.log(table.aSelected);
                table.display_btns();
            });
        });
    });

    return {
        //main function to initiate template pages
        init: function () {
            handleDataTables();
        }
    }
});

谢谢

仍然没有找到如何继续。。。