如果它是根级别的项目,请签入 jQuery 可排序列表

Check in jQuery Sortable list if it is an item on root level

我正在使用 jQuery Sortable。已经可以在多个级别的列表中拖放项目。我如何知道我尝试拖放的项目是否在根级别?

这是我当前的代码:

$("#koppen_sortable").sortable({
            containerSelector: ".sortable-container",
            itemSelector: ".sortable-item",
            handle: 'i.fa-arrows',
            placeholder: '<div class="sortable-item placeholder"> </div>',
            onDrop: moveKopInDocument,
            tolerance: 6
        });

// Move the kop with the document
    var moveKopInDocument = function ($item, container, _super, event) {
        // Handle move base method first
        _super($item, container);

        // here I would like to check if this item current position is a root item or a sub item
    };

我修改如下:

if($item[0].parentElement.parentElement.className !== 'sortable-item') {
            // this is a root item
        } else {
            // this is a sub item
        }