jquery-ui - 从 Jquery UI Sortable 重置位置

标签 jquery-ui jquery-ui-sortable reset

我正在使用 Jquery UI 中的可排序。每次我从 resultPos 获取值时,它都会给我最后一步,但请记住最后的订单。我需要重置它。

例如,我有 3 个元素:

Move 3rd element to 2nd position: end=1&end=3&end=2
Again ...
Move 3rd element to 2nd position: end=1&end=2&end=3
Again ...
Move 3rd element to 2nd position: end=1&end=3&end=2

我需要一些东西可以返回给我以下内容:

Move 3rd element to 2nd position: end=1&end=3&end=2
Again ...
Move 3rd element to 2nd position: end=1&end=3&end=2
Again ...
Move 3rd element to 2nd position: end=1&end=3&end=2

这是我的代码:

$( ".sortableChip" ).sortable({
        revert: true,
        containment: "#carousel",
        axis: "x",
        items: 'li.edited',
        tolerance: 'pointer',
        placeholder: 'draggin-space',
        start: function(event, ui) { 
             var startPos = $('.sortableChip').sortable('serialize',{ key: 'start'});
        },
        sort: function(event, ui) {
            ui.item.addClass('draggin');
            $('.remove-chart').hide();
        },
        update: function(event, ui) {
            var resultPos = $('.sortableChip').sortable('serialize',{ key: 'end'});
            ui.item.removeClass('draggin');
        }
    });

最佳答案

jquery UI 可排序中的每个项目都是一个 LI,有几种方法可以做到这一点,一种方法是在页面最初加载时保存具有可排序列表内容的变量,就像文档就绪部分一样。它所做的只是重新排列 ul 标签内的 li 标签的顺序。

<script type="text/javascript">

    $(document).ready(function(){


         $('#link').click(function(){

            //this will empty out the contents of the ul
            $('.sortableChip').html('');
            /*this will replace the contents of the ul with 
            contents that were caputred 
            */
            $('.sortableChip').html(reset);

        });

    });

    var reset = $('.sortableChip').html();
    /*this is here at the bottom because you want to everything that is created     
    dynamically with jquery or javascript to be captured also.
    */
</script>

您基本上所做的就是在单击链接后返回正确的设置,仅此而已,您实际上不需要此行 `$('.sortableChip').html(''); 但我把它放在这里是为了让你知道它被清空并被替换

如果它们需要根据您点击的内容进行排序,您可以将您想要的状态保存为重置等变量,并简单地清除内容并根据用户点击的内容加载变量

关于jquery-ui - 从 Jquery UI Sortable 重置位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10217490/

相关文章:

css - Webkit CSS 重置

javascript - select2 对齐不起作用

javascript - jQuery-验证使用时间选择器选择的开始时间和结束时间

javascript - 如何将项目拖放到外部容器?

ruby-on-rails - 如何重置我的 Git/Rails 3.1 项目中的所有 Heroku

reporting-services - 有没有办法在 SSRS 参数窗口中有一个重置按钮?

javascript - JQuery 用户界面 : Cancel Sortable upon Droppable Drop

javascript - iPhone 之类的 Javascript/jQuery 重新排序/随机播放小部件

jquery-ui - jQuery UI 可使用 React.js 进行排序