gpt4 book ai didi

javascript - 从 JSON 数组中拼接或删除元素列表

转载 作者:行者123 更新时间:2023-11-30 15:38:50 24 4
gpt4 key购买 nike

我有一个来自 REST API 的 JSON 数组输出,我使用 ng-repeat 在 HTML 上显示这些项目。

var searchresponse = [{
"items": [{
"employeeId": "ABC",
"type": "D",
"alive": "Yes"

}, {
"employeeId": "DEF",
"type": "D",
"alive": "Yes"

}, {
"employeeId": "NPK",
"type": "D",
"alive": "Yes"

}, {
"employeeId": "PKN",
"type": "A",
"alive": "Yes"
}],
"more": false
}];

当用户尝试使用 selectall/single select 删除时,我正在调用 REST API 以从数据库中删除员工 ID。一旦我得到成功的响应,我计划拼接/删除用户从 VIEW 中选择的值。我想删除以下 employeeid 和他们的类型,从 searchresponse 中删除

 var data1=["ABC","NPK"];

应该从搜索响应中删除 data1 具有相应详细信息的任何内容

最佳答案

您只需使用拼接items数组中删除employeeIddata1中的每一项方法。

引用资料

var searchresponse = [{
"items": [{
"employeeId": "ABC",
"type": "D",
"alive": "Yes"

}, {
"employeeId": "DEF",
"type": "D",
"alive": "Yes"

}, {
"employeeId": "NPK",
"type": "D",
"alive": "Yes"

}, {
"employeeId": "PKN",
"type": "A",
"alive": "Yes"
}],
"more": false
}];
var data1=["ABC","DEF"];
var items=searchresponse[0].items;
var i=items.length;
while (i--) {
if(data1.indexOf(items[i].employeeId)!=-1){
items.splice(i,1);
}
}
console.log(searchresponse[0].items);

关于javascript - 从 JSON 数组中拼接或删除元素列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41129661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com