[英]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.