数组分组
//设备数据分组 var device = res.device; //传感器设备的图表; var t = []; for (var j = 0; j < res.device.length; j++) { //数据按照imei过滤分组; t[j] = filterArr(res.data, device[j].imei); //防止新添加设备无数据导致的显示异常; if (t[j] == "") { t[j] = [{"id": device[j].id,"value": "0","time": "2020-01-01 00:00:00","imei": device[j].imei}]; } }
对象数组过滤
//根据设备imei筛选数据; function filterArr(arr, imei) { return arr.filter(item => item.imei == imei); }
Done!