有一个特定的元素我想删除。例如,我想删除下面数组中具有id = 76
的元素。此外,数组可以无限期地组合在一起。
这里的问题是我无法刷新页面,因为我使用Vue.js进行即时操作。如果我能做到这一点,我的下一个问题可能是如何在我现在想要的地方添加元素:(
[
{
"id": 6,
"place": 100,
"header_tr": "KURUMSAL",
"header_en": "CORPORATE",
"content_tr": "kurumsal",
"content_en": "corporate",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:02:36",
"updated_at": "2020-05-24 01:02:36",
"deleted_at": null,
"navigation_sub_categories": [
{
"id": 10,
"navigation_main_category_id": 6,
"navigation_sub_category_id": null,
"place": 100,
"header_tr": "Vizyonumuz ve Misyonumuz",
"header_en": "Vizyonumuz ve Misyonumuz",
"content_tr": "vizyonumuz-ve-misyonumuz",
"content_en": "vizyonumuz-ve-misyonumuz",
"href_tr": "vizyonumuz-ve-misyonumuz",
"href_en": "vizyonumuz-ve-misyonumuz",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:08:59",
"updated_at": "2020-05-24 01:08:59",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 11,
"navigation_main_category_id": 6,
"navigation_sub_category_id": null,
"place": 99,
"header_tr": "Temel Değerlerimiz ve Yönetim Politikamız",
"header_en": "Temel Değerlerimiz ve Yönetim Politikamız",
"content_tr": "Temel Değerlerimiz ve Yönetim Politikamız",
"content_en": "Temel Değerlerimiz ve Yönetim Politikamız",
"href_tr": "Temel Değerlerimiz ve Yönetim Politikamız",
"href_en": "Temel Değerlerimiz ve Yönetim Politikamız",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:09:26",
"updated_at": "2020-05-24 01:09:26",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 12,
"navigation_main_category_id": 6,
"navigation_sub_category_id": null,
"place": 98,
"header_tr": "Organizasyon Yapısı",
"header_en": "Organizasyon Yapısı",
"content_tr": "Organizasyon Yapısı",
"content_en": "Organizasyon Yapısı",
"href_tr": "Organizasyon Yapısı",
"href_en": "Organizasyon Yapısı",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:10:33",
"updated_at": "2020-05-24 01:10:33",
"deleted_at": null,
"navigation_sub_categories": [
{
"id": 19,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 12,
"place": 100,
"header_tr": "Yönetim Kurulu",
"header_en": "Yönetim Kurulu",
"content_tr": "/tr/kurumsal/organizasyon-yapilari/yonetim-kurulu",
"content_en": "/en/kurumsal/organizasyon-yapilari/yonetim-kurulu",
"href_tr": "Yönetim Kurulu",
"href_en": "Yönetim Kurulu",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:13:27",
"updated_at": "2020-05-26 08:58:49",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 20,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 12,
"place": 99,
"header_tr": "Meclis",
"header_en": "Meclis",
"content_tr": "Meclis",
"content_en": "Meclis",
"href_tr": "Meclis",
"href_en": "Meclis",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:13:46",
"updated_at": "2020-05-24 01:13:46",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 21,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 12,
"place": 98,
"header_tr": "Disiplin Kurulu",
"header_en": "Disiplin Kurulu",
"content_tr": "Disiplin Kurulu",
"content_en": "Disiplin Kurulu",
"href_tr": "Disiplin Kurulu",
"href_en": "Disiplin Kurulu",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:14:06",
"updated_at": "2020-05-24 01:14:06",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 22,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 12,
"place": 97,
"header_tr": "Meslek Komiteleri Üyeleri",
"header_en": "Meslek Komiteleri Üyeleri",
"content_tr": "Meslek Komiteleri Üyeleri",
"content_en": "Meslek Komiteleri Üyeleri",
"href_tr": "Meslek Komiteleri Üyeleri",
"href_en": "Meslek Komiteleri Üyeleri",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:14:32",
"updated_at": "2020-05-24 01:14:32",
"deleted_at": null,
"navigation_sub_categories": [
{
"id": 23,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 22,
"place": 100,
"header_tr": "Meslek Altı",
"header_en": "Meslek Altı",
"content_tr": "Meslek Altı",
"content_en": "Meslek Altı",
"href_tr": "Meslek Altı",
"href_en": "Meslek Altı",
"constant_status": "İç Link",
"visible_main_status": "Pasif",
"created_at": "2020-05-24 11:32:00",
"updated_at": "2020-05-24 11:32:00",
"deleted_at": null,
"navigation_sub_categories": [
{
"id": 24,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 23,
"place": 100,
"header_tr": "Meslek Alt Alt",
"header_en": "Meslek Alt Alt",
"content_tr": "Meslek Alt Alt",
"content_en": "Meslek Alt Alt",
"href_tr": "Meslek Alt Alt",
"href_en": "Meslek Alt Alt",
"constant_status": "İç Link",
"visible_main_status": "Pasif",
"created_at": "2020-05-24 11:33:20",
"updated_at": "2020-05-24 11:33:20",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 76,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 23,
"place": 44,
"header_tr": "44",
"header_en": "44",
"content_tr": null,
"content_en": null,
"href_tr": null,
"href_en": null,
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-09-24 12:51:25",
"updated_at": "2020-09-24 12:51:25",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 79,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 23,
"place": 77,
"header_tr": "77",
"header_en": "77",
"content_tr": null,
"content_en": null,
"href_tr": null,
"href_en": null,
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-09-24 12:51:43",
"updated_at": "2020-09-24 12:51:43",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
}
],
"dynamic_fixed_pages": []
}
],
"dynamic_fixed_pages": []
}
],
"dynamic_fixed_pages": []
},
{
"id": 13,
"navigation_main_category_id": 6,
"navigation_sub_category_id": null,
"place": 97,
"header_tr": "Meclis Konuşmaları",
"header_en": "Meclis Konuşmaları",
"content_tr": "Meclis Konuşmaları",
"content_en": "Meclis Konuşmaları",
"href_tr": "Meclis Konuşmaları",
"href_en": "Meclis Konuşmaları",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:11:21",
"updated_at": "2020-05-24 01:11:21",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 14,
"navigation_main_category_id": 6,
"navigation_sub_category_id": null,
"place": 96,
"header_tr": "Logo",
"header_en": "Logo",
"content_tr": "Logo",
"content_en": "Logo",
"href_tr": "Logo",
"href_en": "Logo",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:11:39",
"updated_at": "2020-05-24 01:11:39",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 15,
"navigation_main_category_id": 6,
"navigation_sub_category_id": null,
"place": 96,
"header_tr": "Oda Hesapları",
"header_en": "Oda Hesapları",
"content_tr": "Oda Hesapları",
"content_en": "Oda Hesapları",
"href_tr": "Oda Hesapları",
"href_en": "Oda Hesapları",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:11:58",
"updated_at": "2020-05-24 01:11:58",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 16,
"navigation_main_category_id": 6,
"navigation_sub_category_id": null,
"place": 95,
"header_tr": "Stratejik Planlar ve Çalışma Programları",
"header_en": "Stratejik Planlar ve Çalışma Programları",
"content_tr": "Stratejik Planlar ve Çalışma Programları",
"content_en": "Stratejik Planlar ve Çalışma Programları",
"href_tr": "Stratejik Planlar ve Çalışma Programları",
"href_en": "Stratejik Planlar ve Çalışma Programları",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:12:17",
"updated_at": "2020-05-24 01:12:17",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 17,
"navigation_main_category_id": 6,
"navigation_sub_category_id": null,
"place": 94,
"header_tr": "Kardeş Odalar",
"header_en": "Kardeş Odalar",
"content_tr": "Kardeş Odalar",
"content_en": "Kardeş Odalar",
"href_tr": "Kardeş Odalar",
"href_en": "Kardeş Odalar",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:12:36",
"updated_at": "2020-05-24 01:12:36",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 18,
"navigation_main_category_id": 6,
"navigation_sub_category_id": null,
"place": 94,
"header_tr": "KVKK",
"header_en": "KVKK",
"content_tr": "KVKK",
"content_en": "KVKK",
"href_tr": "KVKK",
"href_en": "KVKK",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:12:55",
"updated_at": "2020-05-24 01:12:55",
"deleted_at": null,
"navigation_sub_categories": [
{
"id": 27,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 18,
"place": 10,
"header_tr": "Test Kvkk Alt",
"header_en": "Test Kvkk Alt EN",
"content_tr": "Test Kvkk Alt",
"content_en": "Test Kvkk Alt EN",
"href_tr": "test-kvkk-alt-tr",
"href_en": "test-kvkk-alt-en",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-09-21 13:10:38",
"updated_at": "2020-09-21 13:10:38",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
}
],
"dynamic_fixed_pages": []
}
]
},
{
"id": 12,
"navigation_main_category_id": 6,
"navigation_sub_category_id": null,
"place": 98,
"header_tr": "Organizasyon Yapısı",
"header_en": "Organizasyon Yapısı",
"content_tr": "Organizasyon Yapısı",
"content_en": "Organizasyon Yapısı",
"href_tr": "Organizasyon Yapısı",
"href_en": "Organizasyon Yapısı",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:10:33",
"updated_at": "2020-05-24 01:10:33",
"deleted_at": null,
"navigation_sub_categories": [
{
"id": 19,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 12,
"place": 100,
"header_tr": "Yönetim Kurulu",
"header_en": "Yönetim Kurulu",
"content_tr": "/tr/kurumsal/organizasyon-yapilari/yonetim-kurulu",
"content_en": "/en/kurumsal/organizasyon-yapilari/yonetim-kurulu",
"href_tr": "Yönetim Kurulu",
"href_en": "Yönetim Kurulu",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:13:27",
"updated_at": "2020-05-26 08:58:49",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 20,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 12,
"place": 99,
"header_tr": "Meclis",
"header_en": "Meclis",
"content_tr": "Meclis",
"content_en": "Meclis",
"href_tr": "Meclis",
"href_en": "Meclis",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:13:46",
"updated_at": "2020-05-24 01:13:46",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 21,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 12,
"place": 98,
"header_tr": "Disiplin Kurulu",
"header_en": "Disiplin Kurulu",
"content_tr": "Disiplin Kurulu",
"content_en": "Disiplin Kurulu",
"href_tr": "Disiplin Kurulu",
"href_en": "Disiplin Kurulu",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:14:06",
"updated_at": "2020-05-24 01:14:06",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
{
"id": 22,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 12,
"place": 97,
"header_tr": "Meslek Komiteleri Üyeleri",
"header_en": "Meslek Komiteleri Üyeleri",
"content_tr": "Meslek Komiteleri Üyeleri",
"content_en": "Meslek Komiteleri Üyeleri",
"href_tr": "Meslek Komiteleri Üyeleri",
"href_en": "Meslek Komiteleri Üyeleri",
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-05-24 01:14:32",
"updated_at": "2020-05-24 01:14:32",
"deleted_at": null,
"navigation_sub_categories": [
{
"id": 23,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 22,
"place": 100,
"header_tr": "Meslek Altı",
"header_en": "Meslek Altı",
"content_tr": "Meslek Altı",
"content_en": "Meslek Altı",
"href_tr": "Meslek Altı",
"href_en": "Meslek Altı",
"constant_status": "İç Link",
"visible_main_status": "Pasif",
"created_at": "2020-05-24 11:32:00",
"updated_at": "2020-05-24 11:32:00",
"deleted_at": null,
"navigation_sub_categories": [
{
"id": 24,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 23,
"place": 100,
"header_tr": "Meslek Alt Alt",
"header_en": "Meslek Alt Alt",
"content_tr": "Meslek Alt Alt",
"content_en": "Meslek Alt Alt",
"href_tr": "Meslek Alt Alt",
"href_en": "Meslek Alt Alt",
"constant_status": "İç Link",
"visible_main_status": "Pasif",
"created_at": "2020-05-24 11:33:20",
"updated_at": "2020-05-24 11:33:20",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},
**{
"id": 76,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 23,
"place": 44,
"header_tr": "44",
"header_en": "44",
"content_tr": null,
"content_en": null,
"href_tr": null,
"href_en": null,
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-09-24 12:51:25",
"updated_at": "2020-09-24 12:51:25",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
},**
{
"id": 79,
"navigation_main_category_id": 6,
"navigation_sub_category_id": 23,
"place": 77,
"header_tr": "77",
"header_en": "77",
"content_tr": null,
"content_en": null,
"href_tr": null,
"href_en": null,
"constant_status": "İç Link",
"visible_main_status": "Aktif",
"created_at": "2020-09-24 12:51:43",
"updated_at": "2020-09-24 12:51:43",
"deleted_at": null,
"navigation_sub_categories": [],
"dynamic_fixed_pages": []
}
],
"dynamic_fixed_pages": []
}
],
"dynamic_fixed_pages": []
}
],
"dynamic_fixed_pages": []
}
]
Salamu Aleykum。尝试:
const filterObject = (object, id) => {
const newObj = [];
object.map((element) => {
if (parseInt(element.id) === parseInt(id)) return;
if (element.navigation_sub_categories)
element.navigation_sub_categories = filterObject(element.navigation_sub_categories, id);
/* Eger `navigation_sub_categories`-den basqa keyde varsa array tipli asagidakini test ede bilersen */
// Object.entries(element).map(
// ([k, v]) => typeof v === "object" && Array.isArray(v) && (element[k] = filterObject(v, id)),
// );
newObj.push(element);
});
return newObj;
};
filterObject(/* object */, idWhicYouNeedDelete)