Given the following list:
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 can we select the parent node of a child with value { name: 'Charge Type 1.2'},
I attempted to use hasChildNodes()
, but it did not work as expected.
var item={ name: 'Charge Type 1.2'};
var parent=getParentElement(item)
The desired output is:
{
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'},
]
},
]
}