Answer the question
In order to leave comments, you need to log in
What are the ways to navigate through the elements in a json structure?
There is a json type structure, tell me what ways you can conveniently navigate through the elements.
I am working with angular js.
Perhaps there is a way to parse this structure for more convenient use?
json:
var menu = [{
icon: 'home',
title: 'Ядро',
path: 'core',
children: [{
title: 'Сайты',
path: 'core_sites'
}, {
title: 'API',
path: 'core_api'
}, {
title: 'Маршруты',
path: 'core_routes'
}]
}, {
icon: 'pencil',
title: 'Персонализация',
path: 'personalization',
children: [{
title: 'Разрешения',
path: 'personalization_permissions'
}, {
title: 'Роли',
path: 'personalization_roles'
}, {
title: 'Пользователи',
path: 'personalization_users'
}, {
title: 'Пользовательские свойства',
path: 'personalization_userproperties'
}, {
title: 'Настройки',
path: 'personalization_settings'
}]
},{
icon: 'globe',
title: 'Домены',
path: 'domain',
children: [{
title: 'Мои домены',
path: 'domain_mydomains'
}]
}];
Answer the question
In order to leave comments, you need to log in
The likeness of a tree. You can navigate recursively:
function doSomethingWithNode(node) {
console.log(node);
}
function processNode(node) {
doSomethingWithNode(node);
node.children.map(processNode);
}
menu.map(processNode);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question