Knockout.js nested sortable bindings

I work with a custom knockout.js plugin; however, I ran into a problem that I still could not solve. I have two sortable bindings: one for buckets and the other for bucketItems. I can reorder bucketItems between buckets; however, I cannot reorder the buckets. Could you imagine why this would be? I also use nested with bindings, but as far as I can tell, this is not what causes the problems.

I would really appreciate any insights you can offer.

+6
source share
1 answer

I do not know your exact structure, but you can use the connectClass option to manage the list of sortable lists. 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 could only remove the bucket in the buckets and the item in the items. The plugin automatically adds the class to the parent element.

Here is an example: http://jsfiddle.net/rniemeyer/YaLgL/

If you do not want to sort items between buckets, you can apply a unique connectClass for each type:

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

+8
source

Source: https://habr.com/ru/post/948246/


All Articles