Bonjour,

Je chercher à convertir une liste d'objet pour avoir en sortie un groupement selon un attribut:

Input:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[
  {
    "AtrLibelle": "1",
    "CatLibelle": "Cat 1"
  },
  {
    "AtrLibelle": "2",
    "CatLibelle": "Cat 1"
  },
  {
    "AtrLibelle": "3",
    "CatLibelle": "Cat 1"
  },
  {
    "AtrLibelle": "4",
    "CatLibelle": "Cat 2"
  },
  {
    "AtrLibelle": "5",
    "CatLibelle": "Cat 2"
  },
  {
    "AtrLibelle": "6",
    "CatLibelle": "Cat 3"
  }
]
output

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[
	{
		"CatLibelle": "Cat 1"
		"Attributs":[{
			"AtrLibelle": "1",
			"CatLibelle": "Cat 1"
		  },{
			"AtrLibelle": "2",
			"CatLibelle": "Cat 1"
		  },{
			"AtrLibelle": "3",
			"CatLibelle": "Cat 1"
		  }
		]
	},{
		"CatLibelle": "Cat 2"
		"Attributs":[{
			"AtrLibelle": "4",
			"CatLibelle": "Cat 2"
		  },{
			"AtrLibelle": "5",
			"CatLibelle": "Cat 2"
		  }
		]
	},{
		"CatLibelle": "Cat 3"
		"Attributs":[{
			"AtrLibelle": "6",
			"CatLibelle": "Cat 3"
		  }3
		]
	}
]
L'utilisation de la lib underscore (http://underscorejs.org/underscore-min.js) permet de faire cela sauf que les attributs seront groupés et affectés à un champ portant le nom de la catégorie. Hors je cherche à avoir un nom générique (CatLibelle par exemple et non pas cat 1, cat 2 cat 3).

Merci d'avance