在页面上有一个列表,有N条记录,它的排序是根据对象中的(sequence Long类型)来排序的!~~~
我现在要实现上移,下移,删除,和添加。
有没有好的办法实现呢,自己想的办法太复杂,想求一个简单高效的方法!~~~~~
各位大大,拜托了! 

解决方案 »

  1.   

    移动直接置换就可以了
    删除直接删除就可以了
    添加insert到指定位置也就可以了~
      

  2.   

    那我重新加载这个页面的时候,顺序不就乱了吗!~~页面显示的顺序是根据数据中的sequence 大小来判断的!·
      

  3.   

    //上移操作
              function toUp(obj){
                  var line = $(obj).parent().parent().parent().parent();
                  if(line.prev()[0]){
                      var downText = line.children(":eq(0)").text();
                      line.children(":eq(0)").text(line.prev().children(":eq(0)").text());
                      line.prev().children(":eq(0)").text(downText);
                      line.insertBefore(line.prev());
                  }
              }
              //下移操作
              function toDown(obj){
                  var line = $(obj).parent().parent().parent().parent();
                  if(line.next()[0]){
                      var upText = line.children(":eq(0)").text();
                      line.children(":eq(0)").text(line.next().children(":eq(0)").text());
                      line.next().children(":eq(0)").text(upText);
                      line.insertAfter(line.next());
                  }
              }
              //删除一行
              function deleteCreative(obj){
                  var line = $(obj).parent().parent().parent();
                  line.nextAll().each(function(){
                      $(this).children(":eq(0)").text($(this).children(":eq(0)").text() - 1);
                  });
                  line.remove();
              }
    画面结构!
    <tr>
                                       <td><s:property value="#VO.playIndex" /></td>
                                       <td><s:property value="#VO.creativeId" /></td>
                                       <td><div><pre><s:property value="#VO.creativeName" /></pre></div></td>
                                       <td><s:property value="#VO.materialCount" /></td>
                                       <td><span id="order1"><span name="moveTo">&uarr;<a href="#" onclick="toUp(this);"><s:text name="ui.toUp" /></a>&nbsp;&nbsp;&darr;<a href="#" onclick="toDown(this);"><s:text name="ui.toDown" /></a></span>&nbsp;&nbsp;<a href="#" name="status" onclick="deleteCreative(this);"><s:text name="ui.delete" /></a></span></td>
                                    </tr>
      

  4.   

    但是如果本来有 A B C三条数据,我把B删了,C数据要上移就要-- 2次 A数据++,所以我移除的时候 必须把比C小的sequence 全部执行一次--,这样就很复杂了呀,跟我的想法就一样拉,这样效率还不高呀。要遍历好多次数据库!!