jquery - How to pass data from the sorting function to be displayed? -


i stored json object global variable this:

var getdata= data;  

//and can append value name property this

 $("#name").on("click",function()  {     $(".the-return").slideup("normal",function()     {         //getdata.responsedata.sort('name');//to call sorting function      (i = 0; < getdata.length; i++) {     $(".the-return2").append("<div class='inside_return'>name:" + getdata[i].name +"</div>");      }      }); }); 

the problem now, want sort before display...so call function this: getdata.responsedata.sort('name');

my sorting function:

getdata.responsedata.sort(function (a, b) {     switch (sortoption) {         case 1:             = a.name,             b = b.name;             type = "string";         case 2:             = a.reputation,             b = b.reputation;             type = "numeric";         // etc     }     if (type == "numeric")     {         // numeric comparison         return > b ? 1 : (a < b ? -1 : 0);     } else if (type == "string") {          // string comparison         return a.localecompare(b);      }     // etc      return; }); 

problem is, unable sort , display data after sorting function called..how initiate call function pass display data after sorted?

i'm thinking call function @ end of sorting function append sorted data div called the-return2 this:

sorting function above ............ ...............

return a.localecompare(b);          }         // etc          return; display_all(b);//to call function append     }); 

appended data:

function display_all(sorted_data) {     (i = 0; < getdata.length; i++) {         $(".the-return2").append("<div class='inside_return'>name:" + getdata[i].name +"</div>");          } } 

****however it's not displaying sorted data!


Comments