2013-12-13 64 views

回答

2

流星不能做到這一點對自己,但你可以用下劃線來做到這一點:

//results from .fetch() 
var results = [{categories:"category 1",name:"etc1"},{categories:"category 1",name:"etc2"}.... 

var grouped = _.groupBy(results, function(item) { 
        return item.categories; 
       }); 

你應該得到這樣的背:

{"category 1":[{"categories":"category 1","name":"etc1"},{"categories":"category 1","name":"etc2"}],"category 2":[{"categories":"category 2","name":"etc3"},{"categories":"category 2","name":"etc"}]} 
相關問題