階層データ構造を構築するために、mjsarfattis nestedSortable Plugin を使用しています。アイテムがネストされないようにする方法はありますか? 例:
phase 1
group
item
item
subgroup
item
item
item
item
item
item
item
phase 2
group
item
item
subgroup
item
item
item
item
ご覧のとおり、(サブ) グループまたはアイテムはフェーズ内にネストできますが、フェーズ自体は別のフェーズまたは (サブ) グループ内にネストすることはできません。
この場合、この関数を処理する「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;
}
}
},
フェーズを別のフェーズ内にドロップしようとすると問題なく動作しますが、もう少し深く (つまり、サブグループ内に) ドラッグしてドロップすると、1 レベル上に「登る」だけです。次に、別のフェーズがあります:-/
フェーズはルート要素のみにする必要があります! 何かアイデアがあれば幸いです。