试图创建一个过滤器以显示数据

发布于 2025-02-10 07:24:48 字数 659 浏览 2 评论 0 原文

我在这里是新手,希望您能帮助我...所以我构建了一个库存应用程序。 有一个Mongo DB表包含产品,每种产品都必须拥有数量和最小的产品。

IM试图在可用数量少于产品的细微量时尝试创建过滤器,它将仅显示桌上的产品。 iv'e添加了两个警报,只是为了测试为什么循环在桌上的第一个产品上堆叠而不是继续以下产品。我希望我提供了足够的信息,谢谢

if (category == "Missing") {
document.querySelectorAll("tbody tr").forEach((element) => {
  alert(Number(document.getElementById("prodMinQuantity").innerText));
  alert(Number(document.getElementById("prodQuantity").innerText));
  if (
    Number(document.getElementById("prodMinQuantity").innerText) >
    Number(document.getElementById("prodQuantity").innerText)
  ) {
    alert("fgfgfg");
    element.style.display = "none";
  }
});

}

im new here and i hope you can help me... so im building an inventory app.
there is a mongo db table contains products and every product have quantity and MinQuantity it must have.

im trying to create a filter when there is less available quantity than the minQuantity of the product it will show only there products in the table.
iv'e added two alerts just to test why the loop is stack on the first product in the table and not moving on to the following products..I hope i gave enough information, thanks

if (category == "Missing") {
document.querySelectorAll("tbody tr").forEach((element) => {
  alert(Number(document.getElementById("prodMinQuantity").innerText));
  alert(Number(document.getElementById("prodQuantity").innerText));
  if (
    Number(document.getElementById("prodMinQuantity").innerText) >
    Number(document.getElementById("prodQuantity").innerText)
  ) {
    alert("fgfgfg");
    element.style.display = "none";
  }
});

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半边脸i 2025-02-17 07:24:48

如果每行包含一个具有IDS prodminquantity prodquantity 的表,则应该更改该列,因为在html id 属性属性必须在文档中是唯一的

最好使用改为存储其他信息。

如果您坚持使用 ID 属性,则可以使用 document.queryselector()而不是:

if (category == "Missing") {
document.querySelectorAll("tbody tr").forEach((element) => {
  const prodMinQuantity = ~~element.querySelector("#prodMinQuantity").innerText,
        prodQuantity = ~~element.querySelector("#prodQuantity").innerText;

  alert(prodMinQuantity);
  alert(prodQuantity);
  if (prodMinQuantity > prodQuantity {
    alert("fgfgfg");
    element.style.display = "none";
  }
});

If you have a table where each row contains columns with ids prodMinQuantity and prodQuantity, you should change that, because in HTML id attribute must be unique in the document.

It's better to use element.dataset to store additional information instead.

If you insist on using id attribute, then you can use document.querySelector() instead:

if (category == "Missing") {
document.querySelectorAll("tbody tr").forEach((element) => {
  const prodMinQuantity = ~~element.querySelector("#prodMinQuantity").innerText,
        prodQuantity = ~~element.querySelector("#prodQuantity").innerText;

  alert(prodMinQuantity);
  alert(prodQuantity);
  if (prodMinQuantity > prodQuantity {
    alert("fgfgfg");
    element.style.display = "none";
  }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文