Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

92
Vistas
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?

6 months ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos