简体   繁体   English

Jquery ui sortables不起作用

[英]Jquery ui sortables don't work

I'm using jquery ui to make a sortable list but it doesn't work and I just can't understand why. 我正在使用jquery ui来制作一个可排序的列表,但它不起作用,我只是无法理解为什么。 The ul element receives the class 'ui-sortable' but nothing happens. ul元素接收类'ui-sortable'但没有任何反应。

I made an example as the original js has many more unrelated objects. 我做了一个例子,因为原始的js有更多不相关的对象。

The example is here . 这个例子在这里 To make it 'work' just click the button with 'editar' in it. 要使其“正常”,只需单击其中包含“editar”的按钮即可。

After wasting a whole weekend with this issue, I ended up understanding what happened. 在整个周末浪费了这个问题后,我最终了解发生了什么。 As this comment points out: when adding elements in the dom using, .html(), it loses its events and data and that's why I wasn't able to clone a previously sortable ul. 正如这篇评论指出的那样:当使用.html()在dom中添加元素时,它会丢失其事件和数据,这就是为什么我无法克隆以前可排序的ul。

I solved my issue assuring that the list was already at the dom before applying the sortable method to it. 我解决了我的问题,确保列表在应用可排序方法之前已经在dom。

Fabrício and Guy, thanks a lot for your help! Fabrício和Guy,非常感谢你的帮助!

If you switch the fiddle to use JQuery 1.7.2 and JQuery ui 1.8.18 it works fine. 如果你切换小提琴使用JQuery 1.7.2和JQuery ui 1.8.18它工作正常。 probably compatibility issues. 可能兼容性问题。 You can see it in my version of your fiddle 你可以在我的小提琴版本中看到它

The error I saw was 我看到的错误是

Uncaught TypeError: Object function ( selector, context ) {
        // The jQuery object is actually just the init constructor 'enhanced'
        return new jQuery.fn.init( selector, context, rootjQuery );
    } has no method 'curCSS' jquery-ui.js:84
(anonymous function) jquery-ui.js:84
(anonymous function) jquery-git.js:5473
jQuery.extend.grep jquery-git.js:709
winnow jquery-git.js:5472
jQuery.fn.extend.filter jquery-git.js:5271
$.fn.extend.scrollParent jquery-ui.js:83
$.widget._mouseStart jquery-ui.js:3026
$.widget._mouseMove jquery-ui.js:677
$.widget._mouseDown._mouseMoveDelegate jquery-ui.js:650
jQuery.event.dispatch jquery-git.js:3060
jQuery.event.add.elemData.handle.eventHandle

I had this same issue. 我有同样的问题。 In my case it was just a matter of finding and removing a duplicate jQuery include <script> tag. 在我的情况下,这只是找到并删除重复的jQuery include <script>标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM