我试图有一个按钮在一个表列,当其点击,我想调用一个服务,从该行的值。可以有人请帮助实现这一点。
function setResponseData(data, length) {
var insertHTML = "<TR class=\"heading\"><TD align=\"center\"> TIMESTAMP </TD><TD align=\"center\"> OPERATION TYPE </TD><TD align=\"center\"> LOG LEVEL </TD><TD align=\"center\"> VERSION </TD><TD align=\"center\"> TYPE </TD><TD align=\"center\"> SESSIONID </TD><TD align=\"center\"> PIECEID </TD><TD align=\"center\"> SHIPMENTID </TD><TD align=\"center\"> SYSTEM ORIGIN </TD><TD align=\"center\"> SYSTEM DESTINATION </TD><TD align=\"center\"> SYSTEM DATAORIGIN </TD><TD align=\"center\"> DIRECT INJECTION ORGANISATION </TD><TD align=\"center\"> PRODUCT </TD><TD align=\"center\"> STATUS </TD><TD align=\"center\"> STATUS CODE </TD><TD align=\"center\"> STATUS MESSAGE </TD><TD align=\"center\"> NODENAME </TD><TD align=\"center\"> PIECENUMBER </TD><TD align=\"center\"> TOTALPIECES </TD><TD align=\"center\"> SYSTEMNAME </TD><TD align=\"center\"> INSERT TIMESTAMP </TD><TD align=\"center\"> EVENT CODE </TD><TD align=\"center\"> CUSTOMERID </TD><TD align=\"center\"> PAYLOAD </TD></TR>";
//var PayloadBtn = document.createElement("BUTTON");
for (var i = 0; i < length; i++) {
var audit = data.results[i];
//var PayloadBtn = document.createElement("BUTTON");
//PayloadBtn.innerHTML = audit.PAYLOAD;
if ((i % 2) == 0) {
insertHTML += "<TR style='background-color:#F0F0E0'>";
} else {
insertHTML += "<TR style='background-color:#E0E0C0'>";
}
if (Boolean(audit.TIMESTAMP)) {
insertHTML += "<TD align=\"center\"> " + audit.TIMESTAMP + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.OPERATIONTYPE)) {
insertHTML += "<TD align=\"center\"> " + audit.OPERATIONTYPE + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.LOGLEVEL)) {
insertHTML += "<TD align=\"center\"> " + audit.LOGLEVEL + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.VERSION)) {
insertHTML += "<TD align=\"center\"> " + audit.VERSION + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.TYPE)) {
insertHTML += "<TD align=\"center\"> " + audit.TYPE + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.SESSIONID)) {
insertHTML += "<TD align=\"center\"> " + audit.SESSIONID + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.PIECEID)) {
insertHTML += "<TD align=\"center\"> " + audit.PIECEID + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.SHIPMENTID)) {
insertHTML += "<TD align=\"center\"> " + audit.SHIPMENTID + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.SYSTEMORIGIN)) {
insertHTML += "<TD align=\"center\"> " + audit.SYSTEMORIGIN + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.SYSTEM_DESTINATION)) {
insertHTML += "<TD align=\"center\"> " + audit.SYSTEM_DESTINATION + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.SYSTEMDATAORIGIN)) {
insertHTML += "<TD align=\"center\"> " + audit.SYSTEMDATAORIGIN + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.DIRECT_INJECTION_ORGANISATION)) {
insertHTML += "<TD align=\"center\"> " + audit.DIRECT_INJECTION_ORGANISATION + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.PRODUCT)) {
insertHTML += "<TD align=\"center\"> " + audit.PRODUCT + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.STATUS)) {
insertHTML += "<TD align=\"center\"> " + audit.STATUS + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.STATUS_CODE)) {
insertHTML += "<TD align=\"center\"> " + audit.STATUS_CODE + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.STATUS_MESSAGE)) {
insertHTML += "<TD align=\"center\"> " + audit.STATUS_MESSAGE + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.NODE_NAME)) {
insertHTML += "<TD align=\"center\"> " + audit.NODE_NAME + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.PIECENUMBER)) {
insertHTML += "<TD align=\"center\"> " + audit.PIECENUMBER + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.TOTALPIECES)) {
insertHTML += "<TD align=\"center\"> " + audit.TOTALPIECES + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.SYSTEM_NAME)) {
insertHTML += "<TD align=\"center\"> " + audit.SYSTEM_NAME + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.INSERT_TIMESTAMP)) {
insertHTML += "<TD align=\"center\"> " + audit.INSERT_TIMESTAMP + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.EVENT_CODE)) {
insertHTML += "<TD align=\"center\"> " + audit.EVENT_CODE + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.CUSTOMERID)) {
insertHTML += "<TD align=\"center\"> " + audit.CUSTOMERID + " </TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
if (Boolean(audit.PAYLOAD)) {
insertHTML += "<TD><input class='myclass' type='button' value='Download' onclick =getPayload(${data.results[i]})/></TD>";
} else {
insertHTML += "<TD align=\"center\"> </TD>";
}
}
document.getElementById("contentTable").innerHTML = insertHTML;
}
function getPayload(audit){
var param = "?";
var flag = "false";
if (audit.VERSION != "" && audit.SESSIONID!= "" && audit.SHIPMENTID!="" && audit.SYSTEM_NAME!="" && audit.TYPE!="") {
param += "shipmentId=" + audit.SHIPMENTID;
param += "version=" + audit.VERSION;
param += "sessionId=" +audit.SESSIONID;
param += "systemName=" + audit.SYSTEM_NAME;
param += "messageType=" + audit.TYPE;
param += "operationType=" + audit.OPERATIONTYPE;
flag = "true";
}
var err = document.getElementById("errorContent");
err.style.display = "none";
var XHR = new XMLHttpRequest();
// We setup our request
XHR.open("GET", "/restv2/getPayloadml" + param);
我想在点击下载按钮时调用getPayload函数,但它没有调用该函数。
我的下载按钮在for循环中,并显示在表列中。当我单击某个特定按钮时,我希望将该行值发送到函数getPayload,因此我给出了onclick =getPayload(${data.results[i].我在这里做错了一些事情,没有调用该函数。
enter image description here
1条答案
按热度按时间ccrfmcuu1#
在浏览器的DOM资源管理器中,检查以下字符串的结果:
你会发现,从字面上看,它是这样的:
这是不正确的:
onclick
属性值周围没有引号。${data.results[i]}
是一个语法错误。看起来你是在尝试使用模板字面量。你还应该在属性值周围使用双引号,而不是单引号。所以字符串字面量(模板字面量)应该是这样的:
请注意使用反引号来 Package 文字和使用双引号来 Package 属性值。浏览器对允许单引号非常宽容,但通常情况下,当您的代码没有按照您的预期运行时,首先要做的是确保它至少在技术上语法正确。