sorting - Javascript sort method -


i working bit of code on website , trying order results member id (i've left comments in code below is) doesnt seem sort order of results though guess must doing wrong. know issue is, , perhaps how limit amount of results shown 10 please?

var httprequestobject = $.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: "/wcf/search.svc/testsearch", datatype: "json", success: function (response) {      if (response != null && response.d != null) {         var data = response.d;         if (data.serviceoperationoutcome == 10) {              var profilelist = data.memberlist;             if (profilelist != null && profilelist.length > 0) {                 (var = 0; < profilelist.length; i++) {                     var profile = profilelist[i];                      // sort var                     var memberid = (profile.memberid);                       if (profile != null) {                         var clonedtemplate = $('.profile-slider #profile').clone();                         $(clonedtemplate).removeattr('style').removeattr('id');                         $(clonedtemplate).find('img').attr("src", profile.thumbnailurl).attr("alt", profile.nickname).wrap('<a></a>');                         $(clonedtemplate).appendto('.profile-slider');                          // sort                         $(memberid).sort();                     }                 }              }         }          else {             alert("error code " + string(data.serviceoperationoutcome));         }     }      else {         alert("null data");     } },  error: function (jqxhr, textstatus, errorthrown) {     alert(errorthrown); } 

});

as adeneo said, want sort member list.

profilelist = profilelist   .filter(function (arg) {return arg !== null;}) // remove nulls   .sort(function(a, b) {     return a.memberid < b.memberid ? -1 : 1; // < operator works numbers or strings   }); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -