Problem with checkbox and datatable?

0

I have a problem, what I want that is through an ajax can get a number of values and make a tour in my datatable that has a checkbox column, and if the value of that checkbox is equal to the value brought by ajax to be checked:

$.ajax({
    url: "/Guias/ListaEquiposGuia",
    type: "GET",
    data: { TipGuia: TipGuia, CodGuia: CodGuia },
    success: function (data) {
        var E = JSON.parse(data)
 //var table = $('#table').datatable();
        table.$('input[type="checkbox"]').each(function () {
        $.each(E, function (i, item) {
            if ($('input[type="checkbox"]').val() == item.CodEquipo)
        $(this).prop('checked', true);
            });
        });
    }
})

You can tell me what I'm doing wrong, Ajax brings me a list of values.

    
asked by Nik.Code 25.10.2018 в 22:13
source

1 answer

1

good at the end the answer is that the each was not going through the JSON array and change it by POST good POst and GET is the least difference is that in GET you have to convert it to obj with JSON.parse but in POST already comes as a good object this was my solution.

$.ajax({
    url: "/Guias/ListaEquiposGuia",
    type: "POST",
    data: { TipGuia: TipGuia, CodGuia: CodGuia },
    success: function (data) {

        for (var i in data) {
            table.$("input[type='checkbox']").each(function () {
                if ($(this).val() == data[i]) {
                    $(this).prop('checked', true);
                }
            });
        }
    }
})
    
answered by 26.10.2018 в 17:08