如何将元素从一个列表移动到另一个列表

How to move elements from one list to another

本文关键字:列表 一个 移动 另一个 元素      更新时间:2023-09-26

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

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

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

问题是,如果我使用一个选项对列表A进行排序,我在列表B上移动的元素会返回到列表A。
你可以从小提琴上看到它!

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

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

有人能帮我吗?

感谢

试试这个:

$('.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);
})
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);
    }) 
});
相关文章: