rniemeyer / knockout-sortable

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

Problems with dynamic templates #150

Closed ryszardnv closed 8 years ago

ryszardnv commented 8 years ago

I have put together a simple fiddle to demonstrate: http://jsfiddle.net/ryszardnv/08w9qw7t/7/. It is based on the connected lists example.

The template for child items is determined by a function. For this example, it always returns the same template, in my production example, the template depends on the child item. In either case, when the child items are dragged and dropped, they appear to be duplicated. However, looking at the target list doesn't show duplicates, unless you reorder the apparent duplicates, when they do seem to get generated in the target list.

If I don't use the getTemplate function, but just directly specify the template name, it works fine. Problem is that I need dynamically select templates, so need to use a function.

Any thoughts?

Thanks Ryszard

rniemeyer commented 8 years ago

@ryszardnv - This is related to #144. You can workaround this issue for now by stripping any whitespace from the top-level elements inside your template like this: http://jsfiddle.net/rniemeyer/bbnfcc0b/

ryszardnv commented 8 years ago

Thanks for responding so quickly! That works perfectly, I've been chasing my tail for a couple of days over this ;~) Thanks again.