我有一个淘汰赛应用程序,其中有一个淘汰赛可观察数组的 div 列表。 将项目移动到新位置后。如何更新 knockoutobservablearray 以反映更改后的顺序?
varsections = document.getElementById('sectionsId');
new Sortable(sections, {
animation: 150,
ghostClass: 'blue-background-class',
//onEnd: function (event) {
//}
onUpdate: function (evt) {
[].forEach.call(evt.from.getElementsByClassName('section-list'), function (el, index) {
el.setAttribute("ordinal", index);
});
}
});
我的淘汰赛类有部分:KnockoutObservableArray = ko.observableArray([]);,它绑定到div列表(部分)。
谢谢您的帮助!
我正在尝试更新序数以触发淘汰可观察以检测变化。没有成功。
您应该在 onUpdate 事件之后对 observableArray 部分中的元素进行排序。然后 KnockoutJS 将自动重新排列 DOM 中的部分。