当前位置: 动力学知识库 > 问答 > 编程问答 >

Ordering by nested json objects with lodash

问题描述:

I have a json file that is requested from a server so i can't modify how is sent, i want to order those objects by a property that is really nested (for example the average property that is located in localidades)

estados(array of objects)

id (property)

name (property)

localidades (array of objects)

id (property)

name (property)

type1 (object)

average (property)

type2 (object) etc..

i only know how to order a simple array of objects in lodash, but not this type of complex object, any hints/suggestions?

here is a json sample :

http://www.jsoneditoronline.org/?id=9cd4c3af94f14b1cca2d35226794ea78

网友答案:

The data does not have an 'average' or even 'avg' field. Here is an example, based on averaging the 'promedio' field for each estado.

What I did is use the _.sortBy with a more advanced predicate.

分享给朋友:
您可能感兴趣的文章:
随机阅读: