Knockout.js nested sortable bindings

安稳与你 提交于 2019-12-07 02:10:31

问题


I am working with the knockout.js sortable plugin; however, I ran into a problem that I have so far been unable to solve. I have two sortable bindings, one for buckets and another for bucketItems. I am able to reorder bucketItems between buckets; however, I am unable to reorder buckets. Would you have any idea why this would be? I am also using nested with bindings, but as far as I can tell, this is not what is causing problems.

I would greatly appreciate any insight you have to offer.


回答1:


I don't know your exact structure, but you can use the connectClass option to control which sortable lists are connected. For example, if you did this:

<ul data-bind="sortable: { data: buckets, connectClass: 'buckets' }">
    <li>
        <span data-bind="text: name"></span>
        <ul data-bind="sortable: { data: items, connectClass: 'items' }">
            <li data-bind="text: name"></li>
        </ul>
    </li>
</ul>

You would only be able to drop a bucket within buckets and an item within items. The plugin automatically adds the class to the parent element.

Here is a sample: http://jsfiddle.net/rniemeyer/YaLgL/

If you did not want to be able to sort items between buckets, then you could apply a unique connectClass to each like:

http://jsfiddle.net/rniemeyer/czNe8/



来源:https://stackoverflow.com/questions/17348270/knockout-js-nested-sortable-bindings

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