在拖放重新排列列表时使用 jQuery SortableJS 淘汰保存重新排序

问题描述 投票:0回答:1

我有一个淘汰赛应用程序,其中有一个淘汰赛可观察数组的 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列表(部分)。

谢谢您的帮助!

我正在尝试更新序数以触发淘汰可观察以检测变化。没有成功。

jquery knockout.js sortablejs
1个回答
0
投票

您应该在 onUpdate 事件之后对 observableArray 部分中的元素进行排序。然后 KnockoutJS 将自动重新排列 DOM 中的部分。

© www.soinside.com 2019 - 2024. All rights reserved.