jquery - remove specific json object from $.cookie -
I have a simple shopping cart where the user adds products to their car. Each added product is saved as a $ .cookie object.
When a user removes a product, the product object is removed from the cookie or the quantity decreases after one. P> My problem is that I am not using the piece correctly, and I did not know how to make this work as a result. What originally happens is the first product object, which is kept from $ .cookie in contrast to the specific object where a match is removed.
Below is my code. I am hoping that one can solve the problem. I suspect that this is "1" (the first element) that is causing the issue >> current_objs.splice (current_objs [i], 1)
this is my code I
$ ('body'). ('Click', '.remove_me', function (e) {var productid = $ (this). Data for ('productid'); var current_objs = $ .cookie ("obj") (i = 0; i & Lt; current_objs.length; i ++) {if (current_objs [i] .productid === productid.toString ()) {if (current_objs [i] .qty == 1) {current_objs.splice (current_objs [i] , $ 1); $ .cookie ("obj", current_objs, {path: '/'});} and {current_objs [i] .qty = current_objs [i] .qty - 1; $ .cookie ("obj" Current_objs, {path: '/'}}}}}}});
Thank you in advance.
javascript array. Splice ()
has the following parameters:
array.splice (index, how many, item 1, item 2, .., itemN)
where
-
Index
is an index for adding / removing items. -
How much is the number of elements to be removed
-
item 1-n
item can be added.
Try it instead:
current_objs. Sister (mother, 1); // Remove 1 item and index I
Comments
Post a Comment