[英]Is it possible to override defined options of the jQuery-ui sortable widget?
我在这里,但问题与我最初的想法不同。
我正在使用的CMS已经为可排序组设置了选项,并且我不想更改它们。 我要做的是从可排序的class
中排除具有"not-sortable"
class
的<div>
。
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
包含更复杂的选择器(例如多重选择器 ),它将失败:
items: ".postbox, .other", // Whoops.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.