假设我有这些行:(表示为 JSON):
[
{ name: "Bob", age: 10 },
{ name: "Carl", age: 15 },
{ name: "Alice", age: 10 },
{ name: "Derek", age: 20 }
]
在 Rails 中,我怎样才能将这些分组age
?例如,我想要这样的东西:
[
{ age: 10, objects: [
{ name: "Bob", age: 10 },
{ name: "Alice", age: 10 }
] },
{ age: 15, objects: [
{ name: "Carl", age: 15 }
] },
{ age: 20, objects: [
{ name: "Derek", age: 20 }
] },
]