JQuery Mobile sort listview after ajax
hello, how are you?, my application shows a listview after bringing data from a db, but I want it to be organized with respect to the value of a field in the db, but it happens that value is in text, numeric variable is in the index, I need to match the two variables to assign the numeric value before the listview is loaded.
I try to use the method sort (), but this only works for organizing the JSON before being loaded.
The value "distancia" is the var i need to asign the numeric value.
- function traerDatos() { try
- { var strHtml = "";
- $.ajax({
- global: false,
- dataType: "html",
- async: false,
- type: "POST",
- url: $("#form").attr('action'),
- data: $("#form").serialize(),
- }).done(function (resultado) {
- var datosRecibidos = JSON.parse(resultado);
- var lista = "";
- $.each( datosRecibidos, function( key, value ) {
- if(value.foto == "nofoto.jpg")
- {
- lista +="<li><div id='imagenproducto'><img src='http://localhost/ServerApp/imagenes/nofoto.jpg' width='60' height='80'></div>";
- }
- else
- {
- lista +="<li><div id='imagenproducto'><img src='http://localhost/ServerApp/imagenes/" + value.foto + "' width='60'></div>";
- }
- lista += "<div id='infoproducto'>";
- lista += "Descripción: " + value.descripcion + "<br>";
- lista += "Precio: " + value.precio + "<br>";
- lista += "Cantidad disponible: " + value.cantidad + "<br>";
- lista += "Direccion: " + value.direccion + "<br>";
- //SE ASIGNA EL VALOR EN METROS AL CAMPO DISTANCIA
- if(value.distancia == "distanciaToTiendaA")
- {
- lista += "Distancia: " + distanciaToTiendaA;
- }
- if(value.distancia == "distanciaToTiendaB")
- {
- lista += "Distancia: " + distanciaToTiendaB;
- }
- if(value.distancia == "distanciaToTiendaC")
- {
- lista += "Distancia: " + distanciaToTiendaC;
- }
- lista += "</div>";
- lista += "</li>";
- lista += "</li>";
-
- });
- $("#listaDatos").html(lista);
- $("#listaDatos").listview().listview('refresh');
- });
- }
- catch(ex)
- {
- alert("Error de datos!");
- }
- }