var PORT_LIST = [ // {"baudrate":9600,"databits":8,"no":1,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0}, // {"baudrate":9600,"databits":8,"no":2,"parity":1,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0}, // {"baudrate":9600,"databits":8,"no":3,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0}, // {"baudrate":9600,"databits":8,"no":4,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0}, // {"baudrate":9600,"databits":8,"no":5,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0}, // {"baudrate":9600,"databits":8,"no":6,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0}, // {"baudrate":9600,"databits":8,"no":7,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0}, // {"baudrate":9600,"databits":8,"no":8,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0}, ]; (function () { //默认查询 query(); // renderTable(); }).call(this); //执行保存 function save() { var dataList = new Array(); var obj = {}; var checked = true; for (var i = 1; i <= PORT_LIST.length; i++) { var cur = PORT_LIST[i-1]; obj.no = $("#no-" + cur.no).val(); obj.baudrate = $("#baudrate-" + cur.no).val(); obj.parity = $("#parity-" + cur.no).val(); obj.databits = $("#databits-" + cur.no).val(); obj.stopbits = $("#stopbits-" + cur.no).val(); obj.timeout = $("#timeout-" + cur.no).val(); obj.pollTime = $("#pollTime-" + cur.no).val(); checked = $("#vld-" + cur.no).prop("checked"); if (checked) { obj.vld = 0; } else { obj.vld = 1; } dataList.push(obj); obj = {}; } // console.log(dataList); $.post("./cgi-bin/sys-port/save", JSON.stringify(dataList), function (data, status) { if ("success" == status && data.code == "success") { window.parent.parent.notify("数据保存成功!"); } else { window.parent.parent.notify("数据保存出错,请重新操作!"); } }, "json"); } //执行查询 function query() { $.get("./cgi-bin/sys-port/query", function (data, status) { if ("success" == status) { PORT_LIST = data; renderTable(); } else { window.parent.parent.notify("数据查询出错,请重新操作!!"); } }, "json"); } //渲染表格 function renderTable() { $("#tbody-data").html(''); // console.log(list); //赋值 var cur; for (var i = 1; i <= PORT_LIST.length; i++) { cur = PORT_LIST[i - 1]; renderTableItem(cur); } } //渲染表格 function renderTableItem(data) { var html = ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += 'ms'; html += ''; html += ''; html += 'ms'; html += ''; html += ''; html += ''; html += ''; html += ''; $("#tbody-data").append(html); $("#no-"+data.no).val(data.no); $("#baudrate-"+data.no).val(data.baudrate); $("#parity-"+data.no).val(data.parity); $("#databits-"+data.no).val(data.databits); $("#stopbits-"+data.no).val(data.stopbits); $("#timeout-"+data.no).val(data.timeout); $("#pollTime-"+data.no).val(data.pollTime); // $("#vld-"+data.on).val(data.vld); if (0 == data.vld || "0" == data.vld) { $("#vld-" + data.no).attr("checked", true); } else { $("#vld-" + data.no).attr("checked", false); } }