get the data from a list with jquery

0

Well that's my concern, through ajax I receive the objects in a list,

listaConfiguracionSucursales = data.lista;

I want to know if there is any way to get all the data of a certain field from that list, now I only receive a value of a given field as follows ipControlador = listaConfiguracionSucursales[$("#comboboxSucursales").val()].ipControlador;

the data of the list I want to obtain belong to the ipController field, but I want the complete list, try with a for cycle, but do not show them in the view, any suggestions? I thank you

Currently this is the way you try to get the data from that list with the for cycle

        .post(
                    'ConsultasRms/tabla_consultaProductos.html',
                    formulario.serialize(),
                    function (data) {
                        $("#loading").hide();

        comboSucursales = document.getElementById('comboboxSucursales');
                    sucursalConsulta = comboSucursales.options[comboSucursales.selectedIndex].text;
                    console.log('contenido1',sucursalConsulta);

                          ipControladores = data.lista;
                          console.log('listaCOMPLETA',ipControladores);

                               for(z = 0; z < ipControladores.length; z++){

                                var datarow = {
                                    sucursal: sucursalConsulta,
                                    numeroSucursal: comboSucursales.options[comboSucursales.selectedIndex].value,
                                    ip: ipControladores[z].ipControlador,

                                };

                                var su = jQuery("#tablaProductoRms")
                                    .jqGrid('addRowData', cont, datarow);
                                    cont++;                 
                           }
    
asked by Jdeveloper 26.12.2016 в 21:50
source

2 answers

3
  

I want to know if there is any way to get all the data of a certain field from that list

The answer is obviously iterating. You say that "it does not show anything in the view" what is a too generic comment, but I suppose you are commenting errors in the iteration. I leave you two ways, the current one and the classic one.

ES2015 :

lista.forEach(item => {
  for (let [k, v] of Object.entries(item)) {
    // aquí k -> llave, v -> valor
  }
});

Traditional :

lista.forEach(function (lista) {
  for (var key in item) {
    var val = item[key];
    // key -> llave, val -> valor
  }
});

jQuery

$.each(lista, function () {
  for (var key in this) {
    var val = this[key];
    // key -> llave, val -> valor
  }
});

This all it does is iterate a list of objects ( {} ) and for each item iterate its entries.

    
answered by 26.12.2016 в 22:09
0

Friend you can use the function each

$.each(data[i].description, function (index, value)
                    {
                        if(index == lang)
                        {
                            option += value;
                        }
                    });

or the foreach that your friend tells you in the answer above. As it is jquery with the function each one should carry out the tour of the list. you can use it within your form to go through the list and the each to get the field you want.

    
answered by 28.12.2016 в 17:02