How do I swap two items in an observableArray?

后端 未结 4 1880
轮回少年
轮回少年 2020-12-03 05:05

I have a button that moves an item one position left in an observableArray. I am doing it the following way. However, the drawback is that categories()[index] gets removed f

4条回答
  •  醉酒成梦
    2020-12-03 05:44

    thanks to Michael Best for his version of moveup

    my version of moveDown

    moveDown: function(category) {
        var array = categories();
        var i = categories.indexOf(category);
        if (i < arr.length) {
            categories.splice(i, 2, array[i + 1], array[i]);
        }
    }
    

提交回复
热议问题