簡體   English   中英

如何將元素從一個列表移動到另一個列表

[英]How to move elements from one list to another

我想將元素從一個列表(A)移至另一列表(B)。
問題是我想對列表A的元素進行排序,並且我正在使用list.js庫,所以女巫非常好。

在這里,您可以看到一切運作方式:

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);
    }) 
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM