gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:49:48 24 4
gpt4 key购买 nike

我正在使用 Jquery UI 中的 sortable。每次我从 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 sortable 中的每个项目都是一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com