I have a list that call ListReorder() method from ListReorder Plugin on that it's work correctly but when add an item to list dynamically and recall ListReorder function on that list don't work on dynamically added list items:
function DragDropList(){
var lists = $('ul#list1').ListReorder();
lists.bind('listorderchanged', function(evt, jqList, listOrder) {
var str="";
for (var i = 0; i < listOrder.length; i++)
{
str += "<div class='gadget'>" + Gadgets[listOrder[i]] + "\n</div>";
}
$("#Preview").contents().find("开发者_C百科.sidebar").html(str);
});
}
//add Gadget
$("#addGadgetBtn").live('click',function()
{
//add new list item here
DragDropList();
}
Probably, you need to use
lists.live();
instead of
lists.bind();
You need to make a change in the plugin and expose its resetList()
method.
Change
function resetList() {
to
this.resetList = function() {
and then after you insert the new elements in the list run $('ul#list1').resetList()
精彩评论