johnny / jquery-sortable

A flexible, opinionated sorting plugin for jQuery
http://johnny.github.io/jquery-sortable/
Other
1.52k stars 441 forks source link

If another list number is full, how to limit the move to it and trigger function? #231

Open amhoho opened 7 years ago

amhoho commented 7 years ago

For example, there are three ul, each UL can only have 10 li. If you drag onto the maximum number of regions, it will be fail and trigger function nextpage();

#1:<ul><li></li><li></li><li></li></ul>
#2:<ul><li></li><li></li><li></li>.....10 li....</ul>
#3:<ul><li></li><li></li><li></li></ul>
#1 or #3 cannot drag to #2 .
If #2 has been moving to #1, #1 reached 10, #2 can no longer move to #1

What should I do to achieve this effect? Thank you!

spidfire commented 6 years ago

Translated from https://github.com/johnny/jquery-sortable/issues/213

            isValidTarget: function ($item, container){
                var depth = 1;
                var maxDepth = 2;
                var children = $item.find('ol').first().find('li');
                //Add the amount of parents to the depth
                depth += container.el.parents('ol').length;
                //Increment the depth for each time a child
                while (children.length) {
                    depth++;
                    children = children.find('ol').first().find('li');
                }
                return depth <= maxDepth
            },