2016-10-20 2 views
0

У меня есть таблица, представляющая весь продукт в корзине клиента, который имеет кнопку «удалить из корзины». Он позволяет пользователю удалить определенный товар в корзине. Вот код:Почему моя таблица ведет себя так?

<form 
     action="${pageContext.request.contextPath}/customer/removeProduct" 
     method="post"> 
     <input type="hidden" name="page" value="${page}"> 
     <table class="table"> 
      <thead> 
       <tr> 
        <th>Name</th> 
        <th>Quantity</th> 
        <th>Amount</th> 
       </tr> 
      </thead> 
      <tbody> 
       <c:forEach items="${productsInCart}" var="product" 
        varStatus="status"> 
        <input type="hidden" class="form-control" name="upc" 
          value="${product.getProduct().getUpc()}"> 
        <tr class="warning"> 

         <td>${product.getProduct().getName()}</td> 
         <td>${product.getQuantity()}</td> 
         <td style="color: green;">&#8369; ${product.totalPrice()}</td> 
         <td><input type="submit" class="btn btn-warning btn-xs" 
          value="Remove from cart"></td> 
        </tr> 
       </c:forEach> 
      </tbody> 
     </table> 
    </form> 

Продукт удаляется путем отправки его UPC (Universal Product Code) в контроллер. Однако, когда нажата кнопка «удалить из корзины», раздаются UPC всех продуктов в корзине. Я не знаю, почему это происходит.

+0

Где «удалить из корзины» код? Если кнопка отправит форму, у нее будут все поля ввода: upc из вашего '$ {productsInCart}' – bhantol

+0

. В последнем, мой друг. saluyotamazing

+0

Получил это. Он отправит форму со всеми UPC, чтобы код вел себя так, как должен. Похоже, вы хотите попытаться удалить только продукт, на который вызывается remove. – bhantol

ответ

0

Исходя из предположения на мой комментарий Вы можете сделать это:

кнопка
<table class="table"> 
    <thead> 
     <tr> 
      <th>Name</th> 
      <th>Quantity</th> 
      <th>Amount</th> 
     </tr> 
    </thead> 
    <tbody> 
     <c:forEach items="${productsInCart}" var="product" 
      varStatus="status"> 
      <form action="${pageContext.request.contextPath}/customer/removeProduct" method="post"> 
       <input type="hidden" name="page" value="${page}"> 
       <input type="hidden" class="form-control" name="upc" 
         value="${product.getProduct().getUpc()}"> 
       <tr class="warning"> 

        <td>${product.getProduct().getName()}</td> 
        <td>${product.getQuantity()}</td> 
        <td style="color: green;">&#8369; ${product.totalPrice()}</td> 
        <td><input type="submit" class="btn btn-warning btn-xs" 
         value="Remove from cart"></td> 
       </tr> 
      </form> 
     </c:forEach> 
    </tbody> 
</table> 
+0

Должен ли я удалить тег

??? – saluyotamazing

+0

Да. Переместите объем формы внутри каждой – bhantol

Смежные вопросы