V
V
Vyacheslav Lebedev2014-12-12 18:20:03
Angular
Vyacheslav Lebedev, 2014-12-12 18:20:03

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

2 answer(s)
N
Nikita Gushchin, 2014-12-12
@slavikse

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);

N
niksee, 2017-04-15
@niksee

writes "remember that you must create directories yourself, InnoDB"
translate the logs!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question