我有以下阵列:AngularJS通过独特的属性值进行过滤,并且过滤的数量
items: [
{
id: "0",
name: "כיבוי אורות",
icon: "rooms_salon.svg",
type: "scenario",
status: 1
},
{
id: "1",
name: "הדלקת אורות",
icon: "rooms_salon.svg",
type: "scenario",
status: 1
},
{
id: "0",
name: "תנור מטבח",
icon: "rooms_salon.svg",
type: "heater",
status: 0
},
{
id: "1",
name: "מזגן מטבח",
icon: "rooms_salon.svg",
type: "ac",
status: 0
}]
我需要过滤,所以我得到的只有唯一的项目。形式和每个项目的原始量的数类型。
的坚决,我需要:
items: [
{
type: "scenario",
amount: 2
},
{
type: "heater",
amount: 1
},
{
type: "ac",
amount: 1
}
]
什么是这样做的最好方法是什么?
P.O:我需要在控制器中过滤它,而不是在ng-repeat中。
感谢配发
阿维
感谢您的回复。 我需要它是一个过滤器,所以当范围内的items数组发生变化时,这也会改变。 再次感谢 Avi – 2014-10-06 12:46:09
如果您想进行更改并将此作为方法添加到您的控制器。 – Sarath 2014-10-06 12:51:28
我需要每个项目被添加到items数组,也将被添加到已过滤的数组 – 2014-10-06 12:54:18