提交 593cc5a0 编写于 作者: S srosengren 提交者: Sebastian Rosengren

Fixed issue with computed foreach's

Fixed how we find correct indexes for items if the sortable is
bound to a filtered collection.
上级 04553782
......@@ -80,7 +80,13 @@
//Unwrapping this allows us to manipulate the actual array
var fromArray = from(),
//It's not certain that the items actual index is the same as the index reported by sortable due to filtering etc.
originalIndex = fromArray.indexOf(itemVM);
originalIndex = fromArray.indexOf(itemVM),
newIndex = e.newIndex;
if (e.item.previousElementSibling)
newIndex = fromArray.indexOf(ko.dataFor(e.item.previousElementSibling));
if (originalIndex > newIndex)
newIndex = newIndex + 1;
//Remove sortables "unbound" element
e.item.parentNode.removeChild(e.item);
......@@ -98,7 +104,7 @@
from.valueHasMutated();
}
//Insert the item on its new position
to().splice(e.newIndex, 0, itemVM);
to().splice(newIndex, 0, itemVM);
//Make sure to tell knockout that we've modified the actual array.
to.valueHasMutated();
};
......@@ -171,4 +177,4 @@
}
};
});
\ No newline at end of file
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册