从 mootools 可排序中删除元素

发布于 2024-12-27 02:24:03 字数 1301 浏览 0 评论 0原文

我正在尝试从 mootools 可排序列表中删除一个项目,然后序列化并保存新列表。

我想在元素上使用一些养眼的东西,而不是直接使用 destroy() 。我在这里构建了一个小提琴: http://jsfiddle.net/kBAqJ/4/

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

如果您使用 nix(true) 而不是 destroy,您将得到 5 作为 order1order2 的值>,尽管文档说 nix(true)dissolve 之后调用 destroy

这是 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);

});

I'm trying to remove an item from a mootools sortable list, then serialize and save the new list.

I'd like to use a little bit of eye-candy rather than a straight destroy() on the element. I've built a fiddle here: http://jsfiddle.net/kBAqJ/4/

Note the order1 and order2 vars. This holds the serialized element before and after removing the item. If you use the destroy method to get rid of the element after removing it from the sortable, you get the right value for order2, eg. 4.

If you use nix(true) instead of destroy, you get 5 as the value of order1 and order2, even though the docs say that nix(true) calls destroy after dissolve.

Is this a bug in Mootools, or am I missing something? Is there a different way to add a dissolve effect while still using destroy that will get the right result?

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

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神爱温柔 2025-01-03 02:24:04

我认为您不会找到任何会破坏元素并仍然在页面上显示它的效果或方式;)所以这不是 moo 工具错误

序列化函数正在使用列表的子项(即 < code>

  • 块)来创建数组。
  • 我想说最简单的方法是在序列化数组中删除它们的引用:

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

    干杯

    i don't think you'll find any effect or way which will destroy the element and still show it on the page ;) So it is not a moo tools bug

    The serialize function is using the children of the list (ie. the <li> blocks) to make the array.

    I would say the easiest way would be to get rid of their reference in the serialized array:

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

    Cheers

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文