我正在尝试从 json 数组中删除一段数据。例如我有这个数组
var favorites = {
"userID": "12345678",
"favorites": [
{ "name" : "My Favorites",
"id" : "87654321",
"items":
[
{
"productID": "11234567",
"added": "TIMESTAMP",
"title": "Project",
"type": "Weekend Project",
"imageURL": "1"
},
{
"productID": "11223456",
"added": "TIMESTAMP",
"title": "Bathroom",
"type": "Weekend Project",
"imageURL": "2"
},
{
"productID": "11223345",
"added": "TIMESTAMP",
"title": "Curves",
"type": "Collections",
"imageURL": "3"
}
]
},
{ "name" : "Bathroom",
"id" : "87654323",
"items":
[
{
"productID": "11122224",
"added": "TIMESTAMP",
"title": "Project",
"type": "Weekend Project",
"imageURL": "1"
},
{
"productID": "11122222",
"added": "TIMESTAMP",
"title": "Room",
"type": "Weekend Project",
"imageURL": "2"
},
{
"productID": "11112222",
"added": "TIMESTAMP",
"title": "Strais",
"type": "Collections",
"imageURL": "3"
},
{
"productID": "11111222",
"added": "TIMESTAMP",
"title": "Door",
"type": "Collections",
"imageURL": "4"
}
]
}
]
}
假设我想通过单击按钮将产品从浴室类别中删除。我将如何实现这一目标?
我一直在尝试这个但无济于事:
jQuery(document).on('click', ".removeFav", function() {
favorites.favorites[1].items[1].splice();
}
我收到的错误:
未捕获的类型错误:对象#没有方法“拼接”