我正在获取一些 JSON 数据,并且正在循环遍历它,并且对于每个数据,我正在创建一个 Anchor 标记,onClick
并且我正在尝试调用一个以对象作为参数的函数。
像这样的东西:
$.getJSON('/ui_dashboard/rest/getAlertDefVsAlertValues',function(data) {
console.log(data)
$("#checkAllAlertsTbody").empty();
var mailServerTbody="";
var objData = data.getAlertDefVsAlertValues;
var objLen = objData.length;
for(var i=0;i<objLen;i++){
//one object for all the key in the json
var alertWholeObject = {
alertFunctionId : objData[i].alertFunctionId,
alertMessage : objData[i].alertMessage,
definitionName:objData[i].definitionName,
emailMessage : objData[i].emailMessage,
emailSubject:objData[i].emailSubject,
emailTemplate : objData[i].emailTemplate,
hubId:objData[i].hubId,
id : objData[i].id,
isDefinitionEnabled:objData[i].isDefinitionEnabled,
mandatoryParam : objData[i].mandatoryParam,
scanInterval:objData[i].scanInterval,
smsMessage : objData[i].smsMessage,
smsTemplateId:objData[i].smsTemplateId,
tenantId : objData[i].tenantId,
timestamp:objData[i].timestamp,
list: objData[i].list,
isArray : function(what){
return Object.prototype.toString.call(what) === '[object Array]';
}
};
console.log(alertWholeObject.alertMessage)
var idWithoutSpace = alertWholeObject.id.replace(/ /g, '');
//for overview table
mailServerTbody = '<tr><td>'+(i+1)+'</td><td>'+alertWholeObject.definitionName+'</td><td>'+alertWholeObject.timestamp+'</td><td>'+
'<div class="controls center">'+
'<a class="btn btn-info btn-mini" id="edit_'+idWithoutSpace+'" onclick="editAlertRules(' + alertWholeObject + ');"><i class="icon-edit icon-white"> </i></a>'+
'<a class="btn btn-danger btn-mini" id="delete_'+idWithoutSpace+'" ><i class="icon-trash icon-white"> </i></a>'+
'</div></td></tr>';
$("#checkAllAlertsTbody").append(mailServerTbody);
}
});
}
但该onclick
功能不起作用;在控制台中仅显示[object object]
。
如何发送在循环中创建的这个对象来点击每个锚标签?
请帮忙。