0

階層データ構造を構築するために、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 レベル上に「登る」だけです。次に、別のフェーズがあります:-/

フェーズはルート要素のみにする必要があります! 何かアイデアがあれば幸いです。

4

2 に答える 2

1

ドキュメントにはエラーがあり、 disableNesting の代わりにdisableNestingClassにする必要があります。それが役立つことを願っています。

于 2013-02-06T08:42:42.903 に答える
1

David - 入れ子にしたくないリスト項目にクラス「no-nest」を与えることができるはずです。例えば:

    <ul id="your-list">
        <li id="listItem_1"><div>Item 1</div></li>
        <li id="listItem_2" class="no-nest"><div>Item 2 (No-Nesting)</div></li>
        <li id="listItem_3"><div>Item 3</div></li>
        <li id="listItem_5"><div>Item 5</div></li>
    </ul>

それが役立つことを願っています!

于 2011-12-08T03:41:28.013 に答える