我正在使用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
};
答案 0 :(得分:0)
我修好了如下:
if($item[0].parentElement.parentElement.className !== 'sortable-item') {
// this is a root item
} else {
// this is a sub item
}