if else 条件在 foreach 中不起作用

发布于 2025-01-10 23:11:58 字数 3512 浏览 0 评论 0原文

我在 foreach 循环中使用 if else 并将该值与容器绑定,但我不明白为什么 if else 条件在 foreach 中不起作用,它在 html 页面中显示 if else 语句,如 if({detailInfo.condition} != = ""){} 但条件不起作用?如何在 div 元素中使用 if else ?

async function renderViewDetails(data, dataTableOrders) {
      let ordersDetails = data.group_id;
      var detailInfos = dataTableOrders;

      let html =
        `<div class="viewDetailModal">
          <div class="detailButtonModal">
            <p class="viewOrderId">ID:</p>
            <p class="orderdetailsid viewOrderId">${data.id}</p>
            <p class="coinviewDetail">${data.coin}</p>
          </div>
          
          <div class="rb-container">
            <ul class="rb">`;

      detailInfos.forEach(detailInfo => {
        if (detailInfo.group_id == ordersDetails) {
          let htmlSegment = `
                  <li class="rb-item timelimeVertical" ng-repeat="itembx">
                    <div class="tradingOrdersInfo">
                    <p class="orderDetailDate">${detailInfo.openedAt}</p>
            
                    <div class="tradeOrderType">
                    <p class="viewDetailOrderType">${detailInfo.type}</p>
                    <button id="showMoreLess_${detailInfo.id}" 
                     data-order-id="${detailInfo.id}" 
                     class="viewDetailOrderButton">View 
                     More</button>
                    </div>
            
                                    
                    <div id="showme_${detailInfo.id}" style="display:none";>
            
                    <div class="tradeOrderEntry">
                    <div>
                    <p class="orderDetailQuantity">Quantity:</p>
                    <p class="orderDetailQuantityValue">${detailInfo.volume}</p>
                   </div>
                   <div class="tradeOrdervaluePrice">
                   <p class="orderPnlInner"> &nbsp; ${detailInfo.group_pnl}</p>
                   <p class="pnlInnerLabel">PNL</p>
                   </div>
                   </div>
            
            
                   <div class="tradeOrderEntry tradeOrderEntryValue">
                   <div>
                   <p class="detailEntryValue entryOpa ">TP Target</p>
                   <p class="detailEntryValue entryOpa">Entry Target</p>
                   </div>
            
 if({detailInfo.condition} !== null){
                   <div>
                   <p class="detailEntryValueR viewPadd">{detailInfo.condition}</p>
                   <p class="detailEntryValueR"> {detailInfo.condition} </p>
                   </div>
                   </div>
            }
            
                   <div class="tradeOrderEntry tradeOrderEntryValue">
                   <div>
                   <p class="detailEntryValue entryOpa">Expire</p>
                   </div>
            
                  
                     </div>
            
                  </div>
                  </li>`

          html += htmlSegment;
        }
      });
      html += `</ul></div></div>`;

      let container = document.querySelector('.orders-details-info');
      container.innerHTML = html;

      }

I am using if else in a foreach loop and binding that value with the container but I don't understand Why if else condition is not working in foreach it is showing if else statement in html page like if({detailInfo.condition} !== ""){} but condition is not working? how can I use if else in a div element?

async function renderViewDetails(data, dataTableOrders) {
      let ordersDetails = data.group_id;
      var detailInfos = dataTableOrders;

      let html =
        `<div class="viewDetailModal">
          <div class="detailButtonModal">
            <p class="viewOrderId">ID:</p>
            <p class="orderdetailsid viewOrderId">${data.id}</p>
            <p class="coinviewDetail">${data.coin}</p>
          </div>
          
          <div class="rb-container">
            <ul class="rb">`;

      detailInfos.forEach(detailInfo => {
        if (detailInfo.group_id == ordersDetails) {
          let htmlSegment = `
                  <li class="rb-item timelimeVertical" ng-repeat="itembx">
                    <div class="tradingOrdersInfo">
                    <p class="orderDetailDate">${detailInfo.openedAt}</p>
            
                    <div class="tradeOrderType">
                    <p class="viewDetailOrderType">${detailInfo.type}</p>
                    <button id="showMoreLess_${detailInfo.id}" 
                     data-order-id="${detailInfo.id}" 
                     class="viewDetailOrderButton">View 
                     More</button>
                    </div>
            
                                    
                    <div id="showme_${detailInfo.id}" style="display:none";>
            
                    <div class="tradeOrderEntry">
                    <div>
                    <p class="orderDetailQuantity">Quantity:</p>
                    <p class="orderDetailQuantityValue">${detailInfo.volume}</p>
                   </div>
                   <div class="tradeOrdervaluePrice">
                   <p class="orderPnlInner">   ${detailInfo.group_pnl}</p>
                   <p class="pnlInnerLabel">PNL</p>
                   </div>
                   </div>
            
            
                   <div class="tradeOrderEntry tradeOrderEntryValue">
                   <div>
                   <p class="detailEntryValue entryOpa ">TP Target</p>
                   <p class="detailEntryValue entryOpa">Entry Target</p>
                   </div>
            
 if({detailInfo.condition} !== null){
                   <div>
                   <p class="detailEntryValueR viewPadd">{detailInfo.condition}</p>
                   <p class="detailEntryValueR"> {detailInfo.condition} </p>
                   </div>
                   </div>
            }
            
                   <div class="tradeOrderEntry tradeOrderEntryValue">
                   <div>
                   <p class="detailEntryValue entryOpa">Expire</p>
                   </div>
            
                  
                     </div>
            
                  </div>
                  </li>`

          html += htmlSegment;
        }
      });
      html += `</ul></div></div>`;

      let container = document.querySelector('.orders-details-info');
      container.innerHTML = html;

      }

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文