简体   繁体   中英

Creating a table of barcodes using JSBarcode

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/jsbarcode@3.11.4/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 id for every barcode was the same which resulted in the same barcode being display multiple times. The solution to this problem is to have a unique id which could be accomplished like this:

id="<%=obj.id%>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM