My JavaScript code snippet is shown below:
function downloadFile(dataItem) {
....
}
....
for (var r = 0; r < dataItems.length ; r++) {
table += '<tr>';
var listOfAttributes = ['CarModel', 'BusMapping', 'Date_', 'Location_', 'Comments', 'AttackTraffic', 'IsTagged']
**table +='<td> <a onclick="downloadFile(dataItems[r])" href="#">' + dataItems[r]['FileName']['S'] +'</a></td>';**
for (var c = 0; c < Object.keys(dataItems[0]).length-1 ; c++) {
table +='<td>' + dataItems[r][listOfAttributes[c]]["S"] +'</td>';
}
table+= '</tr>'
}
An error is occurring on this line of the code:
table +='<td> <a onclick="downloadFile(dataItems[r])" href="#">' + dataItems[r]['FileName']['S'] +'</a></td>';
The issue seems to be that JavaScript cannot resolve the 'dataItems' variable within the -tag:
<a onclick="downloadFile(dataItems[r])" href="#">.
Interestingly, the same variable name resolves successfully in another part of the line:
+ dataItems[r]['FileName']['S'] +
What do you think might be causing this problem? How can I ensure that 'dataItems' is resolved inside the -tag?