0

我有以下问题:

const barcodeValue = element.dataset.barcode;

// the above value is sent as an argument to be verified by the function below..

if(!barcodeValue){

// run code

}

现在dataset.barcode来自数据库......目前在模式中字段条形码不存在。所以我不知道有什么价值,barcodeValue但我认为它是undefined,并且 console.logging 它证实了这一点..

但是,如果我在数据库中添加条形码字段并将其保留为空,barcodeValue 将被视为虚假并且工作正常..因此空字段的值是虚假的,但不存在字段的值(即使它显示为undefined) 不是假的..

但是如果数据库中不存在条形码字段,我认为它会存在undefined并且它仍然可以工作。但它没有..我试图用谷歌搜索但找不到解释..

如果上述问题没有激怒您(就像我之前的查询一样)并且您可以将其视为真正的查询,我将不胜感激。

这是按钮

  <button class="btn ticket__print-ticket" data-id=${user._id} data-barcode=${user.barcode}> Print Ticket </button>
  </div>

这是在事件中发送的论点

  if (modalContent) {
  modalContent.addEventListener("click", function(e) {
    e.preventDefault();

    if (e.target.closest(".ticket__print-ticket")) {
      const printTicketBtn = e.target;
      const id = printTicketBtn.dataset.id;
      const barcode = printTicketBtn.dataset.barcode;

      console.log(id, barcode);

      printTicket(barcode);
    }

这是当数据库字段不存在时不响应的代码(即使它显示为undefined当我 console.log 它时

显示条形码值的图像未定义


export const printTicket = async function(barcode) {
  // console.log(barcode)
  if (!barcode) {
    console.log("in");
    showMessage(
      "Ticket Not Ready",
      "The ticket process requires approval and should be completed soon. You will have a response soon. However you can show the QR Code at the Entrance and generate the ticket immediately"
    );
    return;
  }
4

0 回答 0