Knockout move observableArray item down

From this question, i know how to move an item up:

moveUp: function(category) {
    var i = categories.indexOf(category);
    if (i >= 1) {
        var array = categories();
        categories.splice(i-1, 2, array[i], array[i-1]);
    }
}

What is the equivalent for moving the item down?

Answers


In this solution, i delete two items, from index position, and then again insert them (first - the next item, and the second - moving item):

moveDown = function(number) {
    var i = self.numbers().indexOf(number);
    if (i < self.numbers().length - 1) {
        var rawNumbers = self.numbers();
        self.numbers.splice(i, 2, rawNumbers[i + 1], rawNumbers[i]);
    }
}

Demo


Need Your Help

Windows Script Componets - Are they thread safe

scripting

I need to develop a very simple class developed as a Windows Script Component that needs to work in a multi-threaded environment.

How to log user actions to db using the Zend Framework

php database-design logging versioning

I am building a cms at the moment using the zend framework and have implemented a text based log which will log any errors and allows me to log any custom messages I may want recorded.