淘汰赛举动observableArray项下 [英] Knockout move observableArray item down
本文介绍了淘汰赛举动observableArray项下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从<一个href=\"http://stackoverflow.com/questions/10258086/how-do-i-swap-two-items-in-an-observablearray\">this问题,我知道如何将一个项目了起来:
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?
推荐答案
在这个解决方案,我删除两个项目,从首页
的位置,然后再次插入(第 - 下一个项目,第二个 - 移动项):
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]);
}
}
这篇关于淘汰赛举动observableArray项下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文