jQuery UI Sort-两个列表,防止在原始列表内进行可排序 [英] jQuery UI Sort - two list and prevent sortable inside origin list

查看:55
本文介绍了jQuery UI Sort-两个列表,防止在原始列表内进行可排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的jquery ui示例.基本上我必须列出项目,每个项目都是可排序的.我要完成的工作如下: 取消对同一列表的排序.以一个示例为例,如果我单击列表1上位置1上的元素,然后将其拖动到位置6,然后放下.我想防止这种情况,但是如果我将元素放在列表二中,那就可以了.

I have a simple example of jquery ui. Basicly i have to list of items, each one is sortable. And what i want to accomplish is the following: cancel sorting of the same list. with an example, if I click over an element on position one on list one, then drag it to position 6, and dropped. I want to prevent that, but if i drop the element in list two, that is ok.

我不知道如何指定才能适合我的要求. ConnectWith似乎还不够:

i don't know how to specify, in order to fit my requeriments. ConnectWith seems not to be enough:

$("#sortable").sortable({
    connectWith: [$('#sortable2')]
});

$("#sortable2").sortable({
    connectWith: [$('#sortable')]
});

这是示例:

http://jsfiddle.net/sQeZE/3/

推荐答案

这可能不是您想要的精确,但是您可以绑定到receivestop事件(它们以该顺序触发). receive表示从另一个列表接收到一个列表项.触发此操作后,您可以暂时取消阻止排序. stop始终尝试阻止排序:

This may not be exactly what you are looking for, but you can bind to the receive and stop events (they trigger in that order). receive indicates that a list item was received from another list. When this is triggered, you can temporarily unblock sorting. stop attempts to block sorting at all times:

var blocksort = true;
//Using jQuery 1.6.4, but use `.on` when available
$("#sortable, #sortable2").bind('sortreceive', function () {
    blockSort = false;
}).bind('sortstop', function (e) {
    if (blockSort) {
        e.preventDefault();
    }
    blockSort = true;
});

http://jsfiddle.net/sQeZE/5/

这篇关于jQuery UI Sort-两个列表,防止在原始列表内进行可排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆