Group by/order by On JSON data using javascript/jquery

前端 未结 3 1213
滥情空心
滥情空心 2020-12-29 17:14

I have a JSON data and I need to do something like group by and i asked this question before here but i am not getting any satisfied answer so this time i would like to expl

3条回答
  •  情书的邮戳
    2020-12-29 17:22

    You can do that easily with Underscore.js:

    _.chain(myObject.Apps[0].groups).sortBy("author").groupBy("author").value();
    

    Outputs a JSON object:

    {
     "John":[{"id":"4","name":"test group 4","category":"clinical note","author":"John"}],
     "LKP":[{"id":"2","name":"test group 2","category":"clinical image","author":"LKP"}],
     "RRP":[{"id":"1","name":"test group 1","category":"clinical note","author":"RRP"},{"id":"3","name":"test group 3","category":"clinical document","author":"RRP"}]
    }
    

提交回复
热议问题