检查jQuery可排序列表,如果它是根级别的项目

问题描述 投票:0回答:1

我正在使用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
    };
jquery user-interface jquery-ui-sortable
1个回答
0
投票

我把它固定如下:

if($item[0].parentElement.parentElement.className !== 'sortable-item') {
            // this is a root item
        } else {
            // this is a sub item
        }
© www.soinside.com 2019 - 2024. All rights reserved.