我正在使用mjsarfattis nestedSortable插件來構建一個分層數據結構。 有沒有辦法防止項目被嵌套?舉個例子:jQuery nestedSortable:防止項目被嵌套
phase 1
group
item
item
subgroup
item
item
item
item
item
item
item
phase 2
group
item
item
subgroup
item
item
item
item
正如你所看到的,(子)組或項目可以被嵌套階段,但相themselve不應該被嵌套在另一階段或(子)組內內。
對於這種情況,我用的是處理此功能的「mustBeRoot」屬性:_isAllowed已被修改了一下:
_isAllowed: function(parentItem, levels) {
var o = this.options;
// Are we trying to nest under a no-nest or are we nesting too deep?
if (this.currentItem.hasClass(o.mustBeRoot) && this._getLevel(this.placeholder) != 0) {
this.placeholder.removeClass(o.mustBeRoot).addClass(o.errorClass);
if (this._getLevel(this.placeholder) == 1) {
this.placeholder.removeClass(o.errorClass).addClass(o.mustBeRoot);
}
this.beyondMaxLevels = 1;
} else if (parentItem == null || !(parentItem.hasClass(o.disableNesting))) {
if (o.maxLevels < levels && o.maxLevels != 0) {
this.placeholder.addClass(o.errorClass);
this.beyondMaxLevels = levels - o.maxLevels;
} else {
this.placeholder.removeClass(o.errorClass);
this.beyondMaxLevels = 0;
}
} else {
this.placeholder.addClass(o.errorClass);
if (o.maxLevels < levels && o.maxLevels != 0) {
this.beyondMaxLevels = levels - o.maxLevels;
} else {
this.beyondMaxLevels = 1;
}
}
},
好吧,如果我嘗試刪除另一個階段內的階段能正常工作,但是如果我將它拖得更深一點(即在一個小組內)並放下它,它只會「爬升」一個等級。那麼我在另一個階段有一個階段: -/
階段只應該是根元素!我希望你有任何想法。