rniemeyer / knockout-sortable

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

Template binding not removing original element #117

Closed DegreeDev closed 9 years ago

DegreeDev commented 9 years ago

I've noticed in v0.8.8 the "data-bind : sortable : { data: items, template: 'sample-template' }" is, upon drag complete, not removing the old item.

I've made a fiddle demonstrating it. There are two lists, one using the template binding, one using the anonymous templates. The template binding, does not work properly, while the anonymous template does.

http://jsfiddle.net/thftq3a3/

I've included the source of v0.8.8.

Upon further research, it appears the line below was removed. (Line 209 in v0.8.7 and removed in v0.8.8)

//in KO 3+, nodes outside of the original parent aren't found when trying to dispose, need to do this manually
ko.removeNode(el);

Adding this back in resolves the issue.

Thanks, Matt

rniemeyer commented 9 years ago

@DegreeDev - Extra text nodes around named templates have caused many problems in the sortable functionality. I still want to find a good solution to this that does not require the plugin to insert a new template engine.

So, try doing:

<script type="text/html" id="sample-item-template"><li class="ui-state-default">
            <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
            <!-- ko text: name --><!-- /ko -->
        </li></script>

http://jsfiddle.net/thftq3a3/1/

rniemeyer commented 9 years ago

The latest version (0.9.0) helps strip leading/trailing whitespace from named templates to alleviate this type of issue. Thanks!