javascript - How do I implement an 'order' property with AJAX data? -
i making asynchronous 'get' request using parse api. ajax request returns array of strings may not in right order. have searched on google 'order' property ajax may possess no luck.
this ajax request function called retrieve getting value of text property.
ajax request:
obj.retrieve = function(callback) { $.ajax({ url : 'https://api.parse.com/1/classes/messages', type : 'get', datatype: 'json', contenttype : 'application/json', data : json.stringify({ text : 'value: ', order: "-createdat" // order property go here? }), error : function(data) { console.log('error: ' + data); }, success : function(data) { (var = 0; < data["results"].length; i++) callback(data["results"][i].text); } }); };
tl;dr: each object has field names createdat, updatedat, , objectid parse. ideally, use createdat order. suggestions?
possible solutions:
sort on server side
sort manually:
data['results'].sort(function(a, b) { return a.createdat < b.createdat ? -1 : 1; });
Comments
Post a Comment