rniemeyer / knockout-sortable

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

Get an error after clean data #206

Closed dxvladislavvolkov closed 3 years ago

dxvladislavvolkov commented 3 years ago

I have a simple example where I try to clean data of elements but after it, I get an error Error: cannot call methods on draggable prior to initialization; attempted to call method 'destroy'

So, I researched your source code and found that you are trying to destroy component without any conditions and checkshttps://github.com/rniemeyer/knockout-sortable/blob/master/src/knockout-sortable.js#L430

and I think you need to add something like this: https://github.com/rniemeyer/knockout-sortable/blob/master/src/knockout-sortable.js#L366

To reproduce:

  1. Download the attached example
  2. Run it
  3. Click on the button knockout.zip
rniemeyer commented 3 years ago

@dxvladislavvolkov - your suggested change, looks like a good fix

rniemeyer commented 3 years ago

@dxvladislavvolkov - ok - this is fixed in v1.2.1. Thanks!

dxvladislavvolkov commented 3 years ago

@rniemeyer thank you!