javascript - sorting list items with JQuery - Stack Overflow

I'm trying to use the JQuery UI Sortable plugin to allow a user to change the order or list items

I'm trying to use the JQuery UI Sortable plugin to allow a user to change the order or list items by dragging them with the mouse. The page in question is available here.

The relevant JQuery code is in webapp.js

$("#preferences_list").sortable({
            placeholder: "placeholder",
            forcePlaceholderSize: true,
            update: function(event, ui) {
                var order = $(this).sortable("serialize", {key:'list'});
                $.post("/mypreferences/reorder/", order);
            }
        });
$("#preferences_list").disableSelection();

This should enable the user to re-order the categories by using the to drag them up or down (and when a category is dropped in a new position an AJAX request is fired).

The code above looks the same as that shown on the sortable plugin's demo page, but for some reason it's not working at all

I'm trying to use the JQuery UI Sortable plugin to allow a user to change the order or list items by dragging them with the mouse. The page in question is available here.

The relevant JQuery code is in webapp.js

$("#preferences_list").sortable({
            placeholder: "placeholder",
            forcePlaceholderSize: true,
            update: function(event, ui) {
                var order = $(this).sortable("serialize", {key:'list'});
                $.post("/mypreferences/reorder/", order);
            }
        });
$("#preferences_list").disableSelection();

This should enable the user to re-order the categories by using the to drag them up or down (and when a category is dropped in a new position an AJAX request is fired).

The code above looks the same as that shown on the sortable plugin's demo page, but for some reason it's not working at all

Share edited Aug 26, 2011 at 19:57 Dónal asked Aug 26, 2011 at 19:18 DónalDónal 188k177 gold badges586 silver badges844 bronze badges 2
  • Output from firebug? Error messages? WHYT? – nfechner Commented Aug 26, 2011 at 19:21
  • I provided a link to the page itself, so should be able to see all that yourself – Dónal Commented Aug 26, 2011 at 19:44
Add a ment  | 

3 Answers 3

Reset to default 4

There may be other issues, but first change:

<script type="text/javascript" src="myPreferences_files/jquery-ui-sortable-1.js"></script> 
<script type="text/javascript" src="myPreferences_files/jquery-ui-widget-1.js"></script> 

to:

<script type="text/javascript" src="myPreferences_files/jquery-ui-widget-1.js"></script> 
<script type="text/javascript" src="myPreferences_files/jquery-ui-sortable-1.js"></script> 

You've got sortable.js loading before widget.js. Sortable depends on widget, so widget.js must be included first. Just reorder your script tags.

Look with Firebug on the page you created: there are 4 errors. For example:

jquery-ui-sortable-1.js:17 - Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'widget'

Are you sure you have jquery.ui.widget.js?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744648891a4585781.html

相关推荐

  • javascript - sorting list items with JQuery - Stack Overflow

    I'm trying to use the JQuery UI Sortable plugin to allow a user to change the order or list items

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信