Sort JSON array after $.getJSON excecuted

前端 未结 2 1622
旧巷少年郎
旧巷少年郎 2021-01-26 18:37

I have a working connection between my json object and getJSON(). I can also sort the data i get once with this code, I sorted it on the \'name\' field of the array and it works

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-26 19:17

    You need to create a variable that will store the JSON and use that once the request returns.

    var jsonData;
    $.getJSON(url,function(json){ 
          jsonData = json;
    }); 
    

    Now you can sort the data contained in jsonData.

提交回复
热议问题