2012-04-18 92 views
2

我正在使用jquery UI排序。每次我从resultPos获得值时,它都会给我最后一招,但要记住最后一个订单。我需要重置它。从jquery UI排序重置排序

例如,我有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'); 
     } 
    }); 
+0

This site http://forum.jquery.com/topic/jquery-how-do-i-re-the-original-positions-of-a-sortable-list -using-sort-method不能帮助我:( – todotresde 2012-04-18 20:33:18

回答

3

jQuery UI中的每个项目都是一个LI,有几种方法可以做到这一点,一种方法是保存一个变量rtable列表内容,当页面初始加载时,就像文档就绪部分一样。它所做的是重新排列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(’”)。 但我把它放在这里,所以你知道它正在清空和替换

如果他们需要根据你点击你排序你会保存你希望作为像变量复位和简单地清除内容和负载基于用户点击的变量

+0

谢谢杰西的回答,但不是我在找什么。 – todotresde 2012-05-24 23:55:00

+0

好吧抱歉,我误解了这个问题,你有一个jsbin链接或类似的东西可以看到? – Jesse 2012-05-30 17:57:11