Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui jQuery sortable手动触发sortstop事件_Jquery Ui_Jquery_Jquery Ui Sortable - Fatal编程技术网

Jquery ui jQuery sortable手动触发sortstop事件

Jquery ui jQuery sortable手动触发sortstop事件,jquery-ui,jquery,jquery-ui-sortable,Jquery Ui,Jquery,Jquery Ui Sortable,是否可以手动触发jQuery可排序控件的事件 我尝试了$(选择器).trigger('sortstop'),但似乎什么也没发生 一些相关的HTML: <div data-zone="name"> <div class="section disabled" id="section-1">Some section template 1</div> <div class="section" id="section-2">Some sect

是否可以手动触发jQuery可排序控件的事件

我尝试了
$(选择器).trigger('sortstop')
,但似乎什么也没发生

一些相关的HTML:

<div data-zone="name">
    <div class="section disabled" id="section-1">Some section template 1</div>
    <div class="section" id="section-2">Some section template 2</div>
    <div class="section" id="section-3">Some section template 3</div>
</div>

<button class="trigger-button">Trigger stop</button>

jQueryUI使用事件来通知代码他们的代码发生了什么,而不是相反

您应该寻找可以用来控制可排序对象的方法,而不是试图通过触发事件来控制ui元素:

// Are you looking for this?
$( ".selector" ).sortable( "cancel" );

// Or this?
$( ".selector" ).sortable( "enable" );
$( ".selector" ).sortable( "disable" );
也没有“sortstop”事件。排序完成或即将完成时,会触发“停止”事件和“beforeStop”事件,但这些事件是由可排序对象发送的,而不是由可排序对象读取以执行操作

如果您真正想要的是监听这些事件,以便执行一些操作,那么您可能需要这样做:

$("[data-zone]").on('stop', function(evt, ui) {
    // sortable has notified that it has stopped, do stuff here
});
更多信息可在可排序的jQuery UI文档中找到:

另外,这里是github上的sortable.js源文件


为什么需要手动触发sortstop?你不能把stop函数的内容放到另一个函数中吗?直接调用第二个函数?主要问题是代码中的闭包。虽然我有一个对分区的引用,但每个分区都有一个“切换移动”,可以为该分区进行移动。我正在尝试使用一个body click处理程序来取消移动,因为所有其他控件都是隐藏的。不过,我想我已经解决了这个问题。我将在稍后更新JSFIDLE
$("[data-zone]").on('stop', function(evt, ui) {
    // sortable has notified that it has stopped, do stuff here
});