Good morning I have the following view in the following way:
When switching to another view, what is generated is the following json:
{
"titulo":"Todos los checkbox",
"checkbox":[
{
"identificador":"168511",
"productos_checkbox":[
{
"codCupon":"168511",
"codigo":"30909",
"precio":"48.3",
"cantidad":1,
"idPedido":"28172",
"tipocosto":"0",
"volumennegocio":"43.125",
"cod_cliente":"G136501",
"tipo_cliente":"1",
"tipo_seleccion":1
}
]
},
{
"identificador":"171778",
"productos_checkbox":[
{
"codCupon":"171778",
"codigo":"23853",
"precio":"384.3",
"cantidad":1,
"idPedido":"28172",
"tipocosto":"0",
"volumennegocio":"343.125",
"cod_cliente":"G136501",
"tipo_cliente":"1",
"tipo_seleccion":4
}
]
}
]
}
In other words, the selected chockboxes and their respective products. In such a way that when I want to return to this view, the values must be filled again but this time with the JSON, the JSON I keep in the localStorage, that is to say here I only get it.
How could I do that ?, some idea.
The first time I enter the view, I generate the table dynamically in this 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)
}
});
NOTE: should be taken into account that the table of coupons available at some time when I return to the view can return more coupons therefore more records will be generated in the table but must be filled those who come in the JSON.
and with this function I build the table Products that you have selected .
function productosSeleccionados(){
$(".lista_productos_seleccionado > tr").remove();
var lista_productos_seleccionado = $('.lista_productos_seleccionado');
if (productos_seleccionados.length === 0){
//$('.cupones_bienvenida_todos .cupon_check').attr('disabled', true);
cantidad_cuponseleccionado = 0;
localStorage.setItem("Cupones_Selecionados", cantidad_cuponseleccionado);
}
else{
cantidad_cuponseleccionado = 1;
localStorage.setItem("Cupones_Selecionados", cantidad_cuponseleccionado);
}
$.each(productos_seleccionados, function(i){
$('<tr/>')
.append($('<td/>').addClass('label-cell nuevo-td').text(productos_seleccionados[i].codigo))
.append($('<td/>').addClass('label-cell nuevo-td').text(productos_seleccionados[i].precio))
.append($('<td/>').addClass('label-cell nuevo-td').text(productos_seleccionados[i].cantidad))
.appendTo(lista_productos_seleccionado);
});
}
Thank you very much in advance.