【问题标题】:Items that cloned by Sortable JS which have Select2 inside them are not working由 Sortable JS 克隆且其中包含 Select2 的项目不起作用
【发布时间】:2021-09-06 22:04:20
【问题描述】:

由 Sortable JS 克隆且其中包含 Select2 的项目不起作用。

我尝试销毁并重新初始化,但它似乎不起作用。

jQuery 代码

            $("select").select2();
        function cleanDrop() {
        $(".dropped-area").removeClass("unsetter");
        $(".dropped-area").addClass("setter row");

        $(".placeholder-drop").removeClass("d-flex");
        $(".placeholder-drop").hide();
        }
        function onEndStyle() {
        $(".dropped-area > div").removeClass("col-lg-3 col-md-4");
        $(".dropped-area > div").addClass("col-12 new-style");
        }
        new Sortable(pullContainer, {
        group: {
            name: "shared",
            pull: "clone",
            put: false,
        },
        sort: false,
        animation: 150,
        chosenClass: "xdd",
        ghostClass: "zaa",
        cancel: ".select2",
        onMove: function () {
            cleanDrop();
        },
        });
        new Sortable(targetContainer, {
        group: {
            name: "shared",
            pull: "clone",
        },
        draggable: ".new-style",
        handle: ".handle",
        animation: 150,
        onAdd: function () {
            onEndStyle();
        },
        });

Codepen Link 非常感谢!

【问题讨论】:

    标签: jquery drag-and-drop jquery-select2 sortablejs


    【解决方案1】:

    不幸的是 select2 正在创建一些自定义内部 ID,您必须在克隆/删除后销毁并重新创建 select2。

    【讨论】:

      猜你喜欢
      • 2017-08-26
      • 2019-04-25
      • 2011-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多