2012-01-13 88 views
0

我试图从mootools排序列表中删除一个项目,然后序列化并保存新列表。将元素从可分类的排序列表中删除

我想在元素上使用一点眼睛而不是直的destroy()。我在这里建了一个小提琴:http://jsfiddle.net/kBAqJ/4/

请注意order1order2变量。这将在删除项目之前和之后保存序列化元素。如果您使用destroy方法从可排序的元素中删除元素后删除元素,则可以获得order2的正确值,例如。 4.

如果使用nix(true)而不是destroy,你得到5作为order1order2价值,即使文档说nix(true)电话destroydissolve后。

这是Mootools中的错误,还是我错过了什么?有没有不同的方式来添加dissolve的效果,同时仍然使用destroy会得到正确的结果?

window.addEvent('domready', function(){ 

    var mySort = new Sortables('#example2 UL', { 
     clone: true, 
     revert: true, 
     opacity: 0.7 
    }); 

    console.log (mySort.elements.length); 
    var order1 = mySort.serialize(0); 
    console.dir(order1); 

    mySort.removeItems($('item1')).destroy(); // this results in the correct value in the order2 var below 
    //mySort.removeItems($('item1')).nix({duration: 1000}, true); // this results in the wrong value for order2 

    console.log (mySort.elements.length); 
    var order2 = mySort.serialize(0); 
    console.dir(order2); 

}); 

回答

0

我不认为你会发现任何影响或方式,这将破坏元素仍然显示在页面上;)所以它不是一个哞工具错误

序列化功能使用列表中的孩子(即<li>块)来制作数组。

我想说的最简单的方法是将得到的序列化数组中摆脱其参考的:

window.addEvent('domready', function(){ 

    var mySort = new Sortables('#example2 UL', { 
     clone: true, 
     revert: true, 
     opacity: 0.7 
    }); 

    console.log (mySort.elements.length); 
    var order1 = mySort.serialize(0); 
    console.dir(order1); 

    //mySort.removeItems($('item1')).destroy(); // this results in the correct value in the order2 var below 
    mySort.removeItems($('item1')).nix({duration: 1000}, true); // this results in the wrong value for order2 

    console.log (mySort.elements.length); 
    var order2 = mySort.serialize(0).erase("item1"); // we have to erase the item because he may still be in the list of children at this time… 
    console.dir(order2); 

}); 

干杯

+0

@ romain--感谢,但问题是,'destroy'工作原理预期的,而'nix'没有 - mootools文档说'nix'调用在它解除效果之后销毁 - 所以人们会认为它会和直接的'destroy'一样工作,不是吗? – julio 2012-01-16 17:55:07

+0

@ julio - 这里的问题是你在发生破坏之前调用序列化。 nix发挥作用然后摧毁。在你的例子中,nix启动,需要10000毫秒才能完成,序列化发生在这个延迟期间,然后销毁被调用......我没有看到任何mootools错误,这是我的预期结果... – Romain 2012-01-17 12:12:09