2014-09-26 124 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

相關問題