if binding without container element not working for sortable

一曲冷凌霜 提交于 2019-12-13 02:06:08

问题


I modified a JSFiddle from rniemeyer to illustrate the problem: http://jsfiddle.net/mTqMt/1/

  <div class="container" data-bind="sortable: groupOrItems">
    <!--ko if: type=='Group'-->
    <div>
      <div class="title" data-bind="text: name()"></div>
      <!--here I would actually have a nested sortable-->
    </div>
    <!--/ko-->
    <!--ko if: type=='Item'-->
    <div class="item" data-bind="text: name()"></div>
    <!--/ko-->
  </div>

Firebug says: "TypeError: node is null" line 546 in knockout-latest.debug.js

I tried it with "foreach" instead of "sortable" and then it worked.

Any ideas?


回答1:


The sortable binding and jQuery UI sortable really needs a parent element to grab onto for the stuff that you are sorting.

You would want to at least wrap your whole "item" in an element like:

  <div class="container" data-bind="sortable: groupOrItems">
    <div>
      <!--ko if: type=='Group'-->
      <div>
        <div class="title" data-bind="text: name()"></div>
        <!--here I would actually have a nested sortable-->
      </div>
      <!--/ko-->
      <!--ko if: type=='Item'-->
      <div class="item" data-bind="text: name()"></div>
      <!--/ko-->
    </div>
  </div>

Updated: http://jsfiddle.net/rniemeyer/FSYYb/



来源:https://stackoverflow.com/questions/14218353/if-binding-without-container-element-not-working-for-sortable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!