Javascript 如何在JQuery UI对话框中使ajax加载的UL可排序?

Javascript 如何在JQuery UI对话框中使ajax加载的UL可排序?,javascript,jquery,jquery-ui,jquery-ui-sortable,Javascript,Jquery,Jquery Ui,Jquery Ui Sortable,我需要在后台加载一个UL,然后将其显示在一个对话框中进行排序,但我对JQuery/jqueryui还不熟悉,显然我在谷歌上遇到了麻烦。就我所知: $(document).on('click','a.priority', function(){ // Get the URL of the link var href = $(this).attr('href'); // Tell the page to expect JS instead href = href +

我需要在后台加载一个UL,然后将其显示在一个对话框中进行排序,但我对JQuery/jqueryui还不熟悉,显然我在谷歌上遇到了麻烦。就我所知:

$(document).on('click','a.priority', function(){
    // Get the URL of the link
    var href = $(this).attr('href');
    // Tell the page to expect JS instead
    href = href + "/ajax";
    // Get the page content
    $.get(href, function(data){
        // Initialise a dialog for the content
        var my_dialog = $('<div></div>')
            .dialog({
                 autoOpen: false
                ,open: function (event, ui) {
                    // Add the result of the GET (a UL) as the dialog's content
                    my_dialog.html(data);
                    // Make it sortable, how?
                    my_dialog.sortable().disableSelection();
                    // Set the dialog title (this will be dynamic later, and we might need to call a single dialog that gets remangled rather than creating one every time)
                    my_dialog.dialog("option","title","Change priority");
                }
            });
        // Show the dialog
        wsd_dialog.dialog('open');
    });
    // Don't follow the link
    return false;
});
$(文档).on('click','a.priority',function()){
//获取链接的URL
var href=$(this.attr('href');
//告诉页面使用JS
href=href+“/ajax”;
//获取页面内容
$.get(href,函数(数据){
//初始化内容的对话框
变量my_dialog=$('')
.对话({
自动打开:错误
,打开:函数(事件,用户界面){
//添加GET(UL)的结果作为对话框的内容
my_dialog.html(数据);
//如何使其可排序?
my_dialog.sortable().disableSelection();
//设置对话框标题(稍后将是动态的,我们可能需要调用一个重新调用的对话框,而不是每次创建一个)
my_dialog.dialog(“选项”、“标题”、“更改优先级”);
}
});
//显示对话框
wsd_对话框。对话框(“打开”);
});
//不要跟随链接
返回false;
});
这将获取内容(需要排序的项目的UL)并将其显示在对话框中,但UL显示为单个“可排序”元素

我如何使UL的LI子项可排序,而不是UL本身


有一种感觉这是一个愚蠢的问题,我一定是在文档中遗漏了什么。

看起来您正在调用对话框上的
sortable()
。您需要在对话框中选择列表项,并对以下项目调用
sortable()

my_dialog.find('ul').sortable();

看起来您正在对话框中调用
sortable()
。您需要在对话框中选择列表项,并对这些项调用
sortable()
。我应该更清楚一点-这就是我要问的方法。我尝试在“my_dialog”之后的“my_dialog.sortable().disableSelection();”中放置一个('ul')选择器,但它可能应该是“my_dialog.html.其他东西('ul').sortable()”。尝试
my_dialog.find('ul').sortable()非常好用,谢谢:)你想把它作为一个答案发布,这样我就可以接受了。“wsd_dialog.sortable({items:“li”})”也可以使用-我第一次查看文档时一定没有看到-但是您的方法更好,因为对话框中可能有其他内容。