[英]JQueryUI sortable only works once
I calling JQueryUI.js in a page header then loading the content with AJAX. 我在页面标题中调用JQueryUI.js,然后使用AJAX加载内容。
Jquery drag and drop works one time then quits working. jQuery拖放工作一次,然后退出工作。 If I JqueryUI.js with every AJAX content load it works, but that is extremely slow.
如果我将每个AJAX内容加载到JqueryUI.js中,则它可以工作,但这非常慢。 This is in YII framework
这是在YII框架中
So the whole thing looks like : 所以整个事情看起来像:
Page.php: page.php文件:
$cs->registerScriptFile($baseUrl . '/js/jquery.ui.js');
$cs->registerScriptFile($baseUrl . '/js/product.js');
product.js: product.js:
// need to namespace this to get access to jquery.ui.js sortable function
(function($) {
SORTABLE = {
mySortable: function(inputId) {
$('#sortable-list-left').sortable();
$('#sortable-list-right').sortable();
}
};
}(jQuery));
$(document)
.ready(function() {
function loadRecord(id, sku) {
$.ajax({
data: "id=" + id + "&sku=" + sku + "&project_id=" + urlParam("project"),
url: "/product/ajaxGetRecord",
type: "POST",
success: function(response) {
// process JSON response
var obj = jQuery.parseJSON(response);
// update the html with the new info
$("#productForm")
.html(obj.form);
(function() {
SORTABLE.mySortable(urlParam("project"));
})();
}
});
});
_pagePartial.php : _pagePartial.php:
<div id="productForm">
// dynamic content filled in here
</div>
This namespacing strategy works for all my other JS, but doesn't work for Jquery.ui.js ... it applies the sortable method and I am able to drag and drop one time, but then it no longer works. 这种命名间隔策略适用于我所有其他JS,但不适用于Jquery.ui.js ...它应用了sortable方法,并且我可以拖放一次,但随后不再起作用。
The working option, which is not ideal, is: 不理想的工作选项是:
_pagePartial.php : _pagePartial.php:
// called every single ajax update ... ugh!
$cs->registerScriptFile($baseUrl . '/js/jquery.ui.js');
$('#sortable-list-left').sortable();
$('#sortable-list-right').sortable();
If you don't remove the list holder (such as ul), and you have dynamical li content inside it, you won't have to rebind sortable()
after ajax call. 如果您不删除列表持有人(例如ul),并且其中包含动态li内容,则在ajax调用之后,无需重新绑定
sortable()
。 Otherwise, you replace your list with new HTML content, you have to do it. 否则,您必须用新的HTML内容替换列表,而必须这样做。 Here is example of David Hoerster
这是大卫·霍斯特 ( David Hoerster )的例子
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.