I am trying to create a table of unique barcodes using node, bootstrap, and ejs. Here are the contents of my .ejs file:
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/JsBarcode.all.min.js"</script>
</head>
<body>
<table>
<thead>
<tr>
<th scope="col">Employee</th>
</tr>
</thead>
<tbody>
<% employeeObj.forEach(function(obj) { %>
<tr>
<td><%= obj.id %><svg id="barcode"></svg><script>var employee = '<%= obj.id %>'; JsBarcode("#barcode", employee);</script></td>
</tr>
<% }); %>
</tbody>
</table>
</body>
</html>
For some reason in each row of the table the barcode is being generated, but every barcode is the exact same value. I tried just putting the string value of obj.id in each row and it displays the different values fine.
What am I doing wrong?
I realized my issue was that the
idfor every barcode was the same which resulted in the same barcode being display multiple times. The solution to this problem is to have a uniqueidwhich could be accomplished like this: