soldair / node-qrcode

qr code generator
MIT License
7.46k stars 621 forks source link

Multiple qr codes on page for bulk printing #327

Closed jimmack1963 closed 1 year ago

jimmack1963 commented 1 year ago

Hi, thank you for this work, it's beautiful!

I'm have a problem where all the codes scan to the same value. It feels like a problem with a closure, but I've done what I can to create new copy of the styling component...

let options = { width: 200, height: 200, type: 'svg' } let range = [...Array(count).keys()] range.forEach(labCtr => { console.log(labels[labCtr]) const labelData = JSON.parse(JSON.stringify( labels[labCtr] )) let optionsEach = Object.assign(options, {data: labelData}) let qrCode = new QRCodeStyling(optionsEach) const el = document.getElementById('label' + labCtr) qrCode.append(el) })

soldair commented 1 year ago

i'm not sure how you're setup but im certain that distinct qrcode objects do not share state. look into variable reuse and asyncronous code.