JQuery Mobile sort listview after ajax

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.
  1. function traerDatos() { try
  2.     {  var strHtml = "";
  3.      $.ajax({
  4.             global: false,
  5.             dataType: "html",
  6.             async: false,
  7.             type: "POST",
  8.             url: $("#form").attr('action'),
  9.             data: $("#form").serialize(),
  10.             }).done(function (resultado) {
  11.                 var datosRecibidos = JSON.parse(resultado);
  12.                 var lista = "";
  13. $.each( datosRecibidos, function( key, value ) {  
  14. if(value.foto == "nofoto.jpg")
  15.         {
  16.      lista +="<li><div id='imagenproducto'><img src='http://localhost/ServerApp/imagenes/nofoto.jpg' width='60' height='80'></div>";
  17.          }
  18.                   else
  19.                     {
  20.                       lista +="<li><div id='imagenproducto'><img src='http://localhost/ServerApp/imagenes/" + value.foto + "' width='60'></div>";
  21.                     }
  22.                       lista += "<div id='infoproducto'>";
  23.                       lista += "Descripción: " + value.descripcion + "<br>";
  24.                       lista += "Precio: " + value.precio + "<br>";
  25.                       lista += "Cantidad disponible: " + value.cantidad + "<br>";
  26.      lista += "Direccion: " + value.direccion + "<br>";
  27.  //SE ASIGNA EL VALOR EN METROS AL CAMPO DISTANCIA
  28.      if(value.distancia == "distanciaToTiendaA")
  29.    {
  30.  lista += "Distancia: " + distanciaToTiendaA;
  31. }
  32.      if(value.distancia == "distanciaToTiendaB")
  33. {
  34.      lista += "Distancia: " + distanciaToTiendaB;
  35. }
  36.      if(value.distancia == "distanciaToTiendaC")
  37.    {
  38.      lista += "Distancia: " + distanciaToTiendaC;
  39. }   
  40.  lista += "</div>";
  41.                       lista += "</li>";
  42.      lista += "</li>";
  43.                 });
  44.                 $("#listaDatos").html(lista);
  45.                 $("#listaDatos").listview().listview('refresh');
  46.         });
  47.     }
  48.     catch(ex)
  49.     {
  50.         alert("Error de datos!");
  51.     }
  52. }