Question

I've been using a slightly modified version of the jQueryUI sortable with observableArrays example Ryan Niemeyer put together in this blog post: http://www.knockmeout.net/2011/05/dragging-dropping-and-sorting-with.html. However, I've noticed that when using the latest version of Knockout (3.0) that I've been getting an error when trying to remove an item from an observableArray when running IE8. Here's the JSFiddle: http://jsfiddle.net/klinden/xFyA2/ (note that in order to run this in IE8 you'll need to use draft mode). To duplicate the error try to grab the last item in the list and move it somewhere else. An error will occur on the line: list.remove(item); The error seems to be occurring in the notifySubscribers method of kosubscribable (around line 1012). All other browsers seem to do fine and older versions of Knockout (e.g. 2.2.1) seem to work fine as well (even in IE8).

Was it helpful?

Solution

I looked into this for a little bit. There is some code in KO ends up calling apply with an undefined second argument, which causes errors in old IE.

nodesToDelete.push.apply(nodesToDelete, ko.utils.fixUpContinuousNodeArray(mapData.mappedNodes, domNode));

The second argument is undefined, because dragging the elements around has left the DOM in a state that was unexpected. This could be "fixed" in KO by doing an "|| []" or always returning an array from fixUpContinuousNodeArray. I will do some additional research when I have a chance to make sure I fully understand the issue and will do the KO fix (as it is minor).

For now, I do notice that you will not receive errors if you use the sortable plugin (https://github.com/rniemeyer/knockout-sortable) and a newer version of jQuery/jQuery UI than the fiddle contained. The plugin has additional functionality and bug fixes for a variety of scenarios.

Here is an updated sample: http://jsfiddle.net/rniemeyer/5eVfF/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top