【发布时间】:2015-03-21 18:02:34
【问题描述】:
我真的很感谢这里的一些帮助。我的JSON知识有限,解决不了。
我需要从我通过 JSON 创建的购物车快速视图中删除一个项目。前端似乎可以工作,但它不能,因为它没有从 JSON 对象中删除项目。
JSON 对象的样子。
[
{
"id": 216687,
"productId": 9604505,
"catalogId": 306758,
"name": "xxxxxxxxx1",
"description": "",
"quantity": 1,
"totalPrice": "38,00",
"smallImage": "/images/products/large/xxxxx.jpg",
},
{
"id": 216687,
"productId": 9604503,
"catalogId": 306756,
"name": "xxxxxxxxx1",
"description": "",
"quantity": 1,
"totalPrice": "38,00",
"smallImage": "/images/products/large/xxxxx.jpg",
}
]
jQuery 函数:
//Deleting Items
$(document).on('click', '.shopping-cart .delete i', function(){
var $target = $(this).parent().parent();
var $positions = $('.shopping-cart .item');
$target.hide(300, function(){
$.when($target.remove()).then( function(){
if($positions.length === 1) {
$('.shopping-cart .items-list').remove();
$('.shopping-cart .title').text('Shopping cart is empty!');
}
});
});
});
我认为我没有正确删除该项目。
【问题讨论】:
-
Json 是否存储在某个变量中?
-
你用 JSON 做什么?在页面上呈现一些内容?更新服务器?目前尚不清楚您的jquery代码和json之间的关系是什么。
-
@Mike 我对 json 很不好,我用 this.items 获取对象,因为 globals.items 返回 null。
-
@technophobia,在页面上呈现内容,但我也需要它来在删除项目时修改服务器中的内容
-
@jogesh_pi 这是我发现的第一篇文章没有多大帮助