From a list like this
table:any[] = [
{
name: 'A1 - John Doe',
icon: 'user-name',
bold: true,
code: 'NY',
open: false,
items: [
{
name: 'D3_AIR_ASBJHABSJAS',
icon: 'package',
open: false,
items: [
{
name: 'Charge Type 1',
open: false,
items: [
{
name: 'Charge Type 1.1',
icon: 'departure-nofill',
date: '12/10/2024'
},
{ name: 'Charge Type 1.2'},
{ name: 'Charge Type 1.3'},
{ name: 'Charge Type 1.4',
items: [
{ name: 'Charge Type 2.1'},
{ name: 'Charge Type 2.2'},
{ name: 'Charge Type 2.3'},
]
},
]
},
{
name: 'Charge Type 2',
open: false,
items: [
{ name: 'Charge Type 2.1'},
{ name: 'Charge Type 2.2'},
{ name: 'Charge Type 2.3',
items: [
{ name: 'Charge Type 2.1.1'},
]
},
]
},
{
name: 'Charge Type 3',
items: [
{ name: 'Charge Type 3.1'},
]
},
]
},
{
name: 'Hotel Beach Park',
icon: 'departure-nofill',
date: '12/10/2024'
}
]
},
{name: '567', code: 'NYF',
items: [
{ name: 'Charge Type 3.1'},
]
},
];
how to select it’s parent node by this child value { name: 'Charge Type 1.2'},
tried hasChildNodes()
. But not working.
var item={ name: 'Charge Type 1.2'};
var parent=getParentElement(item)
I want to return like
{
name: 'Charge Type 1',
open: false,
items: [
{
name: 'Charge Type 1.1',
icon: 'departure-nofill',
date: '12/10/2024'
},
{ name: 'Charge Type 1.2'},
{ name: 'Charge Type 1.3'},
{ name: 'Charge Type 1.4',
items: [
{ name: 'Charge Type 2.1'},
{ name: 'Charge Type 2.2'},
{ name: 'Charge Type 2.3'},
]
},
]
}