• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

146
Views
Javascript Sortablejs Serialize

I have function serialize for sortablejs to want result like ['1','2','3','4','5','6','7','8','9','10','11'], and i already try 2 time push array with example function

function serialize(sortable, type, groupIndex = 0) {
    let typeQuery = '';

    if (typeof type === 'undefined' || type === 'group') {
        typeQuery = '.menu-nested';
    } else if (type === 'main') {
        if (typeof groupIndex !== 'undefined' && typeof groupIndex === 'number') {
            var removeVar = '',
                regexMenuGroup = $('div[id*="managegroup-"][data-id="'+groupIndex+'"]'),
                idMenuGroup = regexMenuGroup.attr('id');
    
            removeVar = groupIdMenu[idMenuGroup];
        }

        typeQuery = ''+removeVar;
    }

    var serialized = [],children = [].slice.call(sortable.children);

    for (var i in children) {
        var nested = children[i].querySelector('.menu-nested');

        serialized.push(children[i].dataset[identifier.id]);
        serialized.push(nested ? serialize(nested, 'group') : []);
    }

    return serialized;
}

But result not as expected

[
    "1",
    [],
    "2",
    [
        "3",
        [],
        "4",
        [],
        "5",
        [],
        "6",
        [],
        "7",
        [],
        "8",
        [],
        "9",
        [],
        "10",
        [],
        "11",
        []
    ]
]

Can concat provide this case?

almost 3 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error