如何在drop之后调用函数-jquery sortable

时间:2021-05-27 14:29:59

I am using the jquery sortable library. And my list is sortable (as in I can drag and drop the items in the list like I want to be able to do). But I cannot seem to get a function to trigger after the item is dropped.

我正在使用jquery可排序库。我的列表是可排序的(因为我可以拖放列表中的项目,就像我希望能够做的那样)。但是在删除项目后,我似乎无法触发一个函数。

Also, .sortable() works fine, but I get an error when I try to use .disableSelection();

此外,.sortable()工作正常,但是当我尝试使用.disableSelection()时,我收到错误。

Here is the sample code:

以下是示例代码:

o.onload = function () {
        data = _customization.data;
        for (id in data) {
            li = o.document.createElement("li");
            a = o.document.createElement("a");
            a.className = "module-customization";
            for (id2 in data[id]) {
                if (id2.indexOf("look") > -1) {
                    var temp = data[id][id2];
                    temp = temp.replace(_customization.pageOrigin, "");
                    temp = temp.replace(/([A-Z])/g, ' $1').trim()
                    a.innerHTML = temp;
                    if (a.getAttribute("Visible") != null) {
                        if (a.getAttribute("Visible") == "True") {
                            a.innerHTML = "<strong style=\"color:white\">" +a.innerHTML + "</strong><strong class=\"pull-right\" style=\"color:#d9534f;\" onClick=\"swapVisible(this)\">Hide</strong>";
                        }
                        else {
                            a.innerHTML = "<strong style=\"color:grey\">" + a.innerHTML + "</strong><strong class=\"pull-right\" style=\"color:#5cb85c;\" onClick=\"swapVisible(this)\">Show</strong>";
                            a.childNodes[0].style.setProperty("text-decoration", "line-through");
                        }
                    }
                } else if (id2.indexOf("Order") > -1) {
                    a.setAttribute("Order", data[id][id2]);
                }
                else if (id2.indexOf("Visible") > -1) {
                    a.setAttribute("Visible", data[id][id2]);
                }
                else {
                    a.setAttribute("rowID", data[id][id2]);
                }
            }
            a.Tag = data[id];
            a.id = id;
            li.appendChild(a);
            $(o.document.getElementById(_customization.pageSide)).sortable({
                receive: function (event, ui) {
                    alert("here");
                }
            });
            $(o.document.getElementById(_customization.pageSide)).disableSelection();

            o.document.getElementById(_customization.pageSide).appendChild(li);
        }
    }

For a little bit of context, "o" is a window that has been opened. And I am dynamically creating li elements based on an array - data. All of that works fine, I just thought I would include it all.

对于一些上下文,“o”是一个已经打开的窗口。我正在基于数组动态创建li元素 - 数据。所有这一切都很好,我只是觉得我会把它全部包括在内。

Like I said, .sortable() is apparently working because I can drag and drop the items, but .disableSelection() gives me:

就像我说的那样,.sortable()显然是有效的,因为我可以拖放项目,但.disableSelection()给了我:

$(...).disableSelection is not a function

$(...)。disableSelection不是一个函数

Any ideas why I cant get that function to trigger the alert("here")?

任何想法为什么我不能让该功能触发警报(“这里”)?

Thanks!

1 个解决方案

#1


0  

Outdated jquery ui library. Problem solved.

过时的jquery ui库。问题解决了。

#1


0  

Outdated jquery ui library. Problem solved.

过时的jquery ui库。问题解决了。