js使用filter对json数组对象进行过滤筛选

js使用filter对json数组对象进行过滤筛选

json:

datas:[{
"description": "摄像头01",
"remark": null,
"status_dictText": "正常",
"ipAddr": "192.168.50.143",
"cameraNo": "01",
"id": "c138768415029966431"
}, {
"description": "摄像头02",
"remark": null,
"status_dictText": "正常",
"ipAddr": "192.168.50.143",
"cameraNo": "02",
"id": "c138768415029966432"
}, {
"description": "摄像头03",
"remark": null,
"status_dictText": "正常",
"ipAddr": "192.168.50.143",
"cameraNo": "03",
"id": "c138768415029966433"
}]

以上形式的json对象数组,通过ID,来进行过滤获取数据


let idtemp = 'c138768415029966431'
let temp = this.datas.filter((t) => {
        return t.id == id;
      })

此时  变量temp的值为

[{
"description": "摄像头01",
"remark": null,
"status_dictText": "正常",
"ipAddr": "192.168.50.143",
"cameraNo": "01",
"id": "c138768415029966431"
}]


qrcode