How to add and return an additional (second) attribute in a sortable / nestedSortable response?

I have a list that uses sortable / nestedSortable. I want to return the second attribute. I mean, besides the default id (menuItem_n) returned, I want to return a second attribute, such as a data type. I know that I can configure the attribute and change the default attribute (which is the identifier), but how to add an additional attribute.

For instance:

  <ol class="sortable">
    <li id="menuItem_1" data-type="type_1">Item A1</li>
    <li id="menuItem_2" data-type="type_1">Item A2</li>
    <li id="menuItem_3" data-type="type_1">Item A3</li>
    <li id="menuItem_4" data-type="type_2">Item B1</li>
    <li id="menuItem_5" data-type="type_2">Item B2</li>
    <li id="menuItem_6" data-type="type_2">Item B3</li>
  </ol>

and then pass it with something like:

$('ol.sortable').nestedSortable('serialize', {attribute: 'id, data-type'});
+4
source share
1 answer

, - nestedSortable. , , (). data- * li, toHierarcy. :

  <ol class="sortable">
    <li id="menuItem_1" data-type="type_1">Item A1</li>
    <li id="menuItem_2" data-type="type_1">Item A2</li>
    <li id="menuItem_3" data-type="type_1">Item A3</li>
    <li id="menuItem_4" data-type="type_2">Item B1</li>
    <li id="menuItem_5" data-type="type_2">Item B2</li>
    <li id="menuItem_6" data-type="type_2">Item B3</li>
  </ol>

, :

$('ol.sortable').nestedSortable('toHierarchy');

, :

      array (
        'id' => '1',
        'type' => 'type_1',
      ),
      1 => 
      array (
        'id' => '2',
        'type' => 'type_1',
      ),
      2 => 
      array (
        'id' => '3',
        'type' => 'type_1',
      ),
      3 => 
      array (
        'id' => '3',
        'type' => 'type_2',
      ),
      4 => 
      array (
        'id' => '4',
        'type' => 'type_2',
      ),
      5 => 
      array (
        'id' => '5',
        'type' => 'type_2',
      )

, , . , , . , - , , data- * .

+1

Source: https://habr.com/ru/post/1651645/


All Articles