- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 React 中有一个类似于此的列表
<div id="list">
<Item data-id="1">
<Item data-id="2">
<Item data-id="3">
<Item data-id="4">
<Item data-id="5">
</div>
我正在使用 sortablejs
npm 库进行排序。
现在,我想从排序中排除最后 2 个元素,
下面是我用来排序的函数
import Sortable from 'sortablejs';
let list = document.getElementById('list');
Sortable.create(list, {
ghostClass: 'ghost',
store : {
set: (sortable) => {
// logic to store new order in DB
sortable.destroy();
}
}
});
预期结果:最后 2 个项目应该变成不可拖动的
此外,前 3 个项目不应该低于它们
我怎样才能做到这一点?
类似问题的解决方案在: How to exclude an element from being dragged in sortable list?
我想要在 React 中等效于下面提到的代码:
$(function() {
$('.sortable').sortable();
$('.sortable').disableSelection();
$('.sortable').sortable({ cancel: '.note' });
});
$('.sortable').sortable({
items : ':not(.note)'
});
最佳答案
也许您可以使用“过滤器”配置选项?
var sortable = new Sortable(el, {
// variables
group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] }
sort: true, // sorting inside list
delay: 0, // time in milliseconds to define when the sorting should start
delayOnTouchOnly: false, // only delay if user is using touch
touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event
disabled: false, // Disables the sortable if set to true.
store: null, // @see Store
animation: 150, // ms, animation speed moving items when sorting, `0` — without animation
easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples.
handle: ".my-handle", // Drag handle selector within list items
filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function)
preventOnFilter: true, // Call `event.preventDefault()` when triggered `filter`
draggable: ".item", // Specifies which items inside the element should be draggable
dataIdAttr: "data-id",
ghostClass: "sortable-ghost", // Class name for the drop placeholder
chosenClass: "sortable-chosen", // Class name for the chosen item
dragClass: "sortable-drag", // Class name for the dragging item
swapThreshold: 1, // Threshold of the swap zone
invertSwap: false, // Will always use inverted swap zone if set to true
invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default)
direction: "horizontal", // Direction of Sortable (will be detected automatically if not given)
forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in
fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback
fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body
fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag.
dragoverBubble: false,
removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it
emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it
关于javascript - react : SortableJS: Exclude some last elements from sorting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64800797/
sortablejs 的自动滚动感觉几乎没有用。有时会滞后。我正在开发一个需要平滑滚动的应用程序,类似于它在 react-beautiful-dnd 中的工作方式。当您靠近边缘时它开始缓慢滚动,当您离
我已经提交了 issue here但只是想检查一下你是否可以在这里更快地解决这个问题。 试图从可拖动项目中排除一个项目,但不能从可排序项目中排除——问题是其他元素可以放在它的后面。 SortableJ
我很难在我的 ul 中禁用对特定 li 的排序。我正在使用 SortableJS . Static
我尝试获取可以使用 SortableJS 进行排序的嵌套列表的顺序。 。我的列表如下所示: Titel 1 Titel 2 Titel3
我正在使用 sortablejs 制作拖放列表。我想要两个按钮,一个输出列表元素的当前顺序,另一个只是将当前顺序重置回其原始状态。 我找到了一些关于如何 print the current order
所以我添加了sortablejs给我的blazor应用程序,它的工作原理 - 第一次拖放。 首先,这是发生了什么: Blazor 组件代码: @foreach (var m in manuf
我刚刚在Laravel项目中实现了SortableJS,并希望重新排列某些元素的顺序。我有一个“块”列表,它们都有一个“Order”数据库字段,它是一个整数。我将基于“订单”字段的值以降序显示这些块。
问题 我正在使用 SortableJS构建一个可拖动的树组件。这意味着我的每个 sortable-item s 有一个 toggle-arrow作为打开和关闭 sub-tree 的子元素(如果有的话)
我有一个带有 localStorage 和 SortableJS 的待办事项项目。我遇到问题,当我对待办事项列表进行排序时,它不会更新本地存储。有人可以帮我找出保存排序列表的方法吗?代码如下,但最好访
我有一个组件,简化后看起来像这样: import Sortable from 'react-sortablejs'; class App extends Component { construct
我可以访问拖动元素的 id(参见下面的代码),但不确定如何获取被替换元素的 id。 JS: Sortable.create(selection, { handle: '.bars-move',
我正在使用 react-sortablejs 库。当尝试在列表中移动卡片时。我收到错误: Cannot read property 'map' of undefined 我有一个密集的结构,但它在这里
我正在尝试在使用 Sortable library 创建的可排序 HTML 列表上模拟拖放操作。 .它使用原生 HTML5 API 在列表中实现可拖动元素和排序。 为了模拟这些拖动事件,我找到并修改了
我希望能够从 SortableJS 中拖出一个元素启用未排序列表,并使其消失。我可以将页面的其余部分设为放置目标吗?或者我是否需要第二个列表作为目标(我想我可以让它在拖动开始时出现)。 我正在使用 J
我在 React 中有一个类似于此的列表 我正在使用 sortablejs npm 库进行
我试图使用 angular-sortables 对拖动的(通过 ng-drag-drop 库)列表项进行排序,但似乎也没有使用它。有人能告诉我它是否与 angular 5 兼容吗? 下面是我的代码:
我正在尝试使用这个名为 SortableJS 的 JavaScript 库以及 jQuery & jQuery SortableJS 。我的前端功能可以正常工作,但我的问题是尝试让它通过 AJAX 请
我是一名优秀的程序员,十分优秀!