我的array
为objects
,并且那些objects
包含一个称为children
的属性,它们也为[[objects
,并且重复它们多深(或不深)。
我需要完成两件事
:path
children
属性中的多个级别。将它们连接在一起以获得单个string
例如,按照下面的示例代码,我需要像这样获得三种不同的URL /路由:
[/system-settings1/accounting1/accounting1/etc
/system-settings2/accounting2/accounting2/etc
/system-settings3/accounting3/accounting3/etc
这是我的object
const routes = [
{
path: '/system-settings1',
name: 'global-settings1',
component: 'tabs1',
children: {
path: 'accounting1',
name: 'local-settings1',
components: 'modals1',
children: {
path: 'accounting1',
name: 'local-settings1',
components: 'modals1'
// more children deeply nested(or not)
}
}
},
{
path: '/system-settings2',
name: 'global-settings2',
component: 'tabs2',
children: {
path: 'accounting2',
name: 'local-settings2',
components: 'modals2',
children: {
path: 'accounting1',
name: 'local-settings1',
components: 'modals1'
// more children deeply nested(or not)
}
}
},
{
path: '/system-settings3',
name: 'global-settings3',
component: 'tabs3',
children: {
path: 'accounting3',
name: 'local-settings3',
components: 'modals3',
children: {
path: 'accounting1',
name: 'local-settings1',
components: 'modals1'
// more children deeply nested(or not)
}
}
},
]
const routeParentPaths = routes.map(({path}) => path); const routeChildrenPaths = routes.map(({children}) => children.path); console.log((routeParentPaths.concat(routeChildrenPaths)));
但是我需要找到一种方法来访问其所有子级路径,还要找到一种连接方法,以便每个
一起形成一个正确的URL。object
您找到一个代码示例here。
我有一个对象数组,这些对象包含一个称为子代的属性,它们也是对象,并且它们在深度上(或不)重复多个级别。基本上,我需要完成两个...