Currently I fill a table dynamically in the following way:
var cupones_bienvenida_todos = $('.cupones_bienvenida_todos');
var tipoCupon ='';
$.each(response.data, function (i) {
if (response.data[i].Tipo_cupon == 1){
tipoCupon = "Cupón de 60%";
}
else if(response.data[i].Tipo_cupon == 1){
tipoCupon = "Cupón de 80%";
}
else{
tipoCupon = "Cupón de 100%";
}
$('<tr class="cupones"/>')
.append($('<td/>').addClass('nuevo-td')
.append($('<label/>').addClass('label-radio item-content').text(response.data[i].Cod_Cliente +" - "+response.data[i].Nombre)))
.append($('<td/>').addClass('label-cell nuevo-td').text(tipoCupon))
.append('<div class="cod_cupon" style="display:none">' + response.data[i].Identificador + '</div>')
.append($('<td/>').addClass('label-cell nuevo-td')
.append($('<label/>').addClass('label-checkbox item-content')
.append('<input type="checkbox" name="cupon_check" class="cupon_check" value="' + response.data[i].Identificador + '"/>')
.append($('<span/>').addClass('item-media').append('<i class="icon icon-form-checkbox"></i>'))))
.appendTo(cupones_bienvenida_todos);
if (cantidad_llaves === 0) {
$('.cupon_check').prop('disabled', true)
}
});
llenarVista();
In this table dynamically for each record created dynamically there is a checkbox:
<input type="checkbox" name="cupon_check" class="cupon_check" value="' + response.data[i].Identificador + '"/>
in its value could be 168511
171778
, taking finds that there may be more records, I will select checkboxes with those values.
From those selected checkboxes I generated an arrangement of objects:
checkbox: [
{identificador: "168511", productos_checkbox: Array(1)},
{identificador: "171778", productos_checkbox: Array(1)}
]
When leaving that view, I keep that information in a JSON in the localStorage so when I return to the view I must upload that file and I must select the checkboxes according to their identifier.
This way I am trying to mark the checkboxes according to their identifier but I could not.
function llenarVista(){
var item_chequeado = [];
if(json_cupones_welcome){
json_cupones_welcome_parse = JSON.parse(json_cupones_welcome);
$.each(json_cupones_welcome_parse.checkbox, function (index,value) {
$.each(value.productos_checkbox, function(index,producto){
productos_seleccionados.push(producto);
});
console.log(value);
item_chequeado.push(true);
});
console.log(item_chequeado);
$('.cupones_bienvenida_todos > tr').each(function(index, value){
var cupones = $(this).closest('.cupones');
cupones.find('.cupon_check').attr('checked',item_chequeado[index]);
console.log(cupones);
});
productosSeleccionados();
}
}