2014-09-26 122 views
0

我想将元素从一个列表(A)移动到另一个列表(B)。
问题是,我想对列表A的元素进行排序,并且我使用list.js库,女巫非常好。
如何将元素从一个列表移动到另一个列表

在这里你可以看到一切是如何工作的:

http://jsfiddle.net/Danny182/yzeupzrt/15/

的问题是,如果我用一个选项进行排序列表中,我名录B移动的元素追溯到名单A.
你可以从小提琴中看到它!

这是我使用的是从一个列表元素移动到另一个代码:

$('.add').click(function() { 
    var id = this.id; 
    $("li#p-"+ id + "").detach().appendTo('#your-team'); 

有人能帮助我吗?

谢谢

+0

你'jsFiddle'不是很直观。如何测试?什么是预期? – melancia 2014-09-26 18:31:10

+0

也许现在好多了! @MelanciaUK – Danny182 2014-09-26 18:42:26

+0

你想对listA进行排序? list.js为你做了什么? – mcgraw 2014-09-26 18:49:04

回答

0

试试这个:

$('.add').click(function() { 
    var id = this.id; 
    //$('#your-team').append($("li#p-"+ id + "").html()); 
    $("li#p-"+ id + "").detach().appendTo('#your-team'); 

    //$("li#p-"+ id + "").remove(); 
    userList = new List('players', options); 
    //userList = new List('players', options); 
}) 
+0

让我知道这是否适合你。 – Prashant19sep 2014-09-26 20:17:53

+0

只需在全局声明变量“userList”即可。 – Prashant19sep 2014-09-26 20:21:16

+0

谢谢,但它不起作用。试试这种方式:http://jsfiddle.net/Danny182/yzeupzrt/24/ – Danny182 2014-09-26 20:27:18

0
var userList; 
$(document).ready(function(){ 
//FUNCTION TO SORT THE LIST A. 
    var options = { 
     valueNames: ['teame', 'role', 'name', 'value', 'team' ] 
    }; 

    userList = new List('players', options); 

    $('#teams').change(function() { 
     var selection = this.value; 
     console.log (selection); 
     if (selection == "tutte") { 
      userList.filter(); 
      return false; 
     } 
     userList.filter(function(item) { 

     if (item.values().team == selection) { 
      return true; 
     } else { 
      return false; 
     } 
     }); 
     return false; 
    }); 
    //THIS FUNCTION DETACHES THE ELEMENTS FROM LIST A AND IT APPENDS IT TO THE LIST B 
    $('.add').click(function() { 
     var id = this.id; 
     //$('#your-team').append($("li#p-"+ id + "").html()); 
     $("li#p-"+ id + "").detach().appendTo('#your-team'); 
     //$("li#p-"+ id + "").remove(); 
     userList = new List('players', options); 
     //userList = new List('players', options); 
    }) 
}); 
+0

在这种方式,他们不回到列表A,但他们总是从列表B消失 – Danny182 2014-09-26 20:32:03

+0

有一段时间我会让你知道。 – Prashant19sep 2014-09-26 20:33:01

+0

它只适用于**选择** – Danny182 2014-09-26 20:36:05

相关问题