Sort JSON alphabetically

前端 未结 5 1154
我寻月下人不归
我寻月下人不归 2021-01-02 13:08

I have a JSON object generated based on data stored in a table. I then need to be able to sort it in different ways, but when I do JSON.stringify(array) and try

5条回答
  •  清歌不尽
    2021-01-02 13:39

    If your intent is to allow the user to sort the table dynamically, then my approach may be slightly different.

    There are plenty of jQuery table sorting plugins. I have had good success with this one: http://tablesorter.com/docs/

    Allows multi-column sort, a default sort, wire up to events, etc... etc...

    This way you can build your table as you already are, and sorting can be done secondary even before page output.

提交回复
热议问题