javascript - Viewing items in a cart which is an array of objects -


i'm trying build oo shopping cart in javascript. i've got adding random products cart , can click basket.

how iterate on basket items can have remove button beside each record?

i thinking along these lines:

    <body>         <form action="#">             <button onclick="cart().add();">add random product</button>             <button onclick="cart().getbasket();">view cart</button>         </form>          <script type="text/javascript">              (var i=0; < cart().getbasket().length; i++){                 console.log(cart().getbasket()[i]);             }         </script>          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>         <script src="shopping-cart.js"></script>         <script>             $(document).ready(function(){                 c$();             });         </script> 

this have far.

i'm thinking of having renderbasket() method can append dom. thoughts?

as shoppingcart array, can use each function jquery iterate on it.

$("#shoppingcart").each(function( index, element) {     console.log(index, element); }); 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -