2016-12-30 100 views
0

嗨,大家好,我有此JSON對象:如何使用控制器水平GROUPBY濾波器角JS

var myData=[{"agence":"CTM","secteur":"Safi","serie":"CZC1448YZN"},{"agence":"CTM","secteur":"Safi","serie":"2UA13817KT"},{"agence":"CTM","secteur":"Rabat","serie":"CZC1349G1B"},{"agence":"CTM","secteur":"Rabat","serie":" 2UA0490SVR"},{"agence":"CTM","secteur":"Agdal","serie":" G3M4NOJ"},{"agence":"CTM","secteur":"Essaouira","serie":" CZC1221B85"},{"agence":"Gare Routiere Municipale","secteur":"Essaouira","serie":" CZC145YL3"}] ; 

我想是通過過濾器在contriller級別使用一組爲這樣的結果:

-Safi 
     -CTM 
      CZC1448YZN 
      2UA13817KT 

-Rabat 
     -CTM 
      CZC1349G1B 
      2UA0490SVR 
     -Agdal 
      G3M4NOJ 
-Essaouira 
     -CTM 
      CZC1221B85 
     -Gare Routiere Municipale 
      CZC145YL3 

是possible..hepl請.. PS:我不想通過過濾器在NG-重複指令使用組,但我想用它在控制器

+0

你試過用Lodash? https://lodash.com/docs/4.17.3#groupBy –

回答

0

你試過也許索姆ething像(與Lodash支持):

$scope.myVarGrouped= _.groupBy(myData,'agence'); 
+0

感謝您的回答,但它給了我一個錯誤....無法讀取屬性'groupBy'的未定義 –

+0

你neeed安裝lodash之前..導入CDN ..或通過NPM –

+0

等待我會嘗試 –