1
我按類別得到了與如何按屬性對我的集合進行分組?
{categories:"category 1",name:"etc1"},{categories:"category 1",name:"etc2"},{categories:"category 2",name:"etc3"},{categories:"category 2",name:"etc"}.
這樣一個集合,在取......哪能組?
我按類別得到了與如何按屬性對我的集合進行分組?
{categories:"category 1",name:"etc1"},{categories:"category 1",name:"etc2"},{categories:"category 2",name:"etc3"},{categories:"category 2",name:"etc"}.
這樣一個集合,在取......哪能組?
流星不能做到這一點對自己,但你可以用下劃線來做到這一點:
//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"}]}