返回文本类型空值
success: function (res) { //获取最新的采集时间; if (typeof(res.data[0]) == "undefined") { $("#curTime").html("00:00:00") } else { $("#curTime").html(res.data[0].time.slice(10)); } }
返回对象数组空值
//传感器设备的图表; 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-00-00 00:00:00", "imei": device[j].imei }]; } }
二次循环
//循环执行图表渲染; var dataName = [], dataList = []; for (var i = 0; i < t[j].length; i++) { dataName.push(t[j][i].time); dataList.push({name: t[j][i].time, value: parseFloat(t[j][i].value).toFixed(2)}); //渲染图表; getLine(dataName, dataList, 't' + device[j].id); }
Done!