rniemeyer / knockout-sortable

A Knockout.js binding to connect observableArrays with jQuery UI sortable functionality
MIT License
547 stars 128 forks source link

Containerless Knockouts aren't evaluated inside sortable #147

Closed sc-moonlight closed 9 years ago

sc-moonlight commented 9 years ago

When I have a containerless if inside a sortable it is not evaluated ignored.

I was able to create a simple example on jsfiddle to demonstrate [https://jsfiddle.net/scfiddle/v6khuLkz/]

<!-- This shows four buckets, instead of two -->
<ul data-bind="sortable: buckets" class="buckets">
<!-- ko if:bool -->
<li data-bind="if: bool"><!-- ko text: name --><!-- /ko --></li>
<!-- /ko -->
</ul>
<!-- this shows two buckets -->
<ul data-bind="foreach: buckets">
<!-- ko if:bool -->
<li data-bind="if: bool"><!-- ko text: name --><!-- /ko --></li>
<!-- /ko -->
</ul>
rniemeyer commented 9 years ago

@sc-moonlight - The sortable binding expects a single element inside the parent container and strips anything else, as it causes problems with the sorting logic. For now, you would have to pre-filter your list or hide things with visible binding.

sc-moonlight commented 9 years ago

OK. So it's stripping any containerless binding right? I tried a containerless template and that failed as well. I rewrote my side to be a visible template binding, selecting the template based on an observable instead of using a ko:if.

Yes, I ran into the single element issue, which is why I was trying to use a containerless binding to only have one element be there. Could probably tweak the selector used to get the correct index of the item to move, but the template works for me at this point