I am trying to pass an array of objects in a onclick function inside a for loop. The scope of the array is inside the for loop only, So I cannot do like this. A sample of my code is as follows:
for (var j = 0; j < globalVariables.countryColl.length; j++) {
var testArray = $.map(empCatgry2Arr, function (e, i) {
return {
Id: e.ID,
company: e.Company,
dept: e.Department
}
});
html += "<tr>" +
"<td>" + globalVariables.countryColl[j].Title + "</td>" +
'<td class="fc-green" onclick="ShowEmployeeDetails(' + testArray + ')">' + empCatgry2Count + '</td>' +
"</tr>";
}
html += "</tbody></table>";
$("#tablediv").append(html);
But when I inspect the page, the HTML looks like : "<td class="fc-green"><a onclick="showEmployeeDetails([object Object])">1</td>"
Initially I was trying to pass the whole empCatgry2Arr array, I have used the map function only to use required key-values.