gpt4 book ai didi

javascript - 是否可以覆盖 jQuery-ui 可排序小部件的定义选项?

转载 作者:行者123 更新时间:2023-11-28 07:17:27 24 4
gpt4 key购买 nike

我正在尝试做什么

我是here但问题与我最初的想法不同。

我使用的 CMS 已经为可排序组设置了选项,但我不想更改它们。我想做的是排除 <div>class"not-sortable"无法排序。

CMS 中包含的当前设置

    $('.meta-box-sortables').sortable({
placeholder: 'sortable-placeholder',
connectWith: '.meta-box-sortables',
items: '.postbox',
handle: '.hndle',
cursor: 'move',
delay: ( isMobile ? 200 : 0 ),
distance: 2,
tolerance: 'pointer',
forcePlaceholderSize: true,
helper: 'clone',
opacity: 0.65,
});

如上所述,我设置了 'postbox' 之一具有附加类别 'not-sortable' 的部分。然后在自定义.js文件我有以下内容。

我的自定义设置

jQuery(function($) {
$(".meta-box-sortables").sortable({
items : ':not(.not-sortable)'
});
});

这将删除移动任何先前可拖动部分的能力。因此,似乎我正在覆盖 items:选项。

有没有办法可以在不覆盖原始设置的情况下做到这一点,或者我的思路是错误的?

最佳答案

您可以使用 option 的形式接受对象的方法:

jQuery(function($) {
$(".meta-box-sortables").sortable("option", {
items: ":not(.not-sortable)"
});
});

这样,您未指定的设置将被保留。

详细说明之前存储在 item 选项中的选择器,不幸的是您必须再次指定它:

items: ".postbox:not(.not-sortable)"

连接到先前的值是可行的:

items: $(".meta-box-sortables").sortable("option", "items")
+ ":not(.not-sortable)"

但是,如果 items 包含更复杂的选择器(例如 multiple selector ),则会失败:

items: ".postbox, .other",  // Whoops.

关于javascript - 是否可以覆盖 jQuery-ui 可排序小部件的定义选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30696012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com