var testList=[ {"passcode":"1","name":"通道号1","value":"0"}, {"passcode":"2","name":"通道号2","value":"1"}, {"passcode":"3","name":"通道号3","value":"0"}, {"passcode":"4","name":"通道号4","value":"0"}, {"passcode":"5","name":"通道号5","value":"1"}, {"passcode":"6","name":"通道号6","value":"0"}, {"passcode":"7","name":"通道号7","value":"1"}, {"passcode":"8","name":"通道号8","value":"0"} ]; var deviceList = []; if (TEST_TAG) { deviceList = testList; renderDeviceData(); }else{ //定时器,每15秒查询一次;查询设备信息并渲染 queryData(); setInterval(queryData,15 * 1000); } //查询设备信息 function queryData() { $.get("./cgi-bin/do/query", function (data, status) { if ("success" == status) { deviceList = data; renderDeviceData(); } else { window.parent.parent.notify("系统获取基础设备列表出错!"); } }, "json"); } //渲染设备列表 function renderDeviceData() { var html = ""; $.each(deviceList, function (index, item) { html += "" + item.passcode + ""; html += "输出量" + item.passcode + ""; if(item.value==0){ html += "断开"; html += ""; }else{ html += "闭合"; html += ""; } html += ""; }); $("#deviceList").html(html); } //输出量控制 function setData(index) { var param = { passcode : deviceList[index].passcode, value : deviceList[index].value == 0 ? 1 : 0 }; console.log(param); $.post("./cgi-bin/do/set", JSON.stringify(param), function (data, status) { if ("success" == data.code) { queryData() } else { window.parent.parent.notify("操作失败!" + data.msg); } }, "json"); }