是否可以覆盖jQuery-ui可排序小部件的已定义选项? [英] Is it possible to override defined options of the jQuery-ui sortable widget?
问题描述
我在此处,但是这个问题与我最初的想法不同.
I was here but the problem was different to what I first thought.
我使用的CMS已经为可排序组设置了选项,并且我不想更改它们.我想做的是将<div>
和"not-sortable"
的class
排除在可排序范围之外.
I'm using a CMS that has set options for the sortable group already and I don't want to change them. What I do want to do is exclude a <div>
with the class
of "not-sortable"
from being 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
文件中,我有以下内容.
As stated above, I've set one of the 'postbox'
sections with an additional class of 'not-sortable'
. Then in a custom .js
file I have the following.
我的自定义设置
jQuery(function($) {
$(".meta-box-sortables").sortable({
items : ':not(.not-sortable)'
});
});
这将使您无法移动任何先前可拖动的部分.因此,似乎我要覆盖items:
选项.
This then removes the ability to move any previously draggable sections. Therefore it seems as though I'm overriding the items:
option.
有没有办法可以在不覆盖原始设置的情况下执行此操作,还是我的思路错了?
Is there a way I can do this without overriding the original settings, or am I wrong in my train of thought here?
推荐答案
您可以使用
这样,未指定的设置将被保留. This way, the settings you don't specify will be preserved. 关于先前存储在 The elaborate upon the selector previously stored in the 连接到先前的值是可行的: Concatenating to the previous value is feasible: 但是,如果 It will, however, fail if 这篇关于是否可以覆盖jQuery-ui可排序小部件的已定义选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!item
选项中的选择器的详细说明,很遗憾,您必须再次指定它:item
option, you unfortunately have to specify it again:items: ".postbox:not(.not-sortable)"
items: $(".meta-box-sortables").sortable("option", "items")
+ ":not(.not-sortable)"
items
包含更复杂的选择器(例如多个选择器),它将失败):items
contains a more complex selector (such as a multiple selector):items: ".postbox, .other", // Whoops.