我有一个表,在添加新记录后替换所有行 - 所有这些都使用 ajax 调用发生,因此无需重新加载。
一旦在容器中替换了记录,tableDnD 似乎不再适用于新记录 - 我必须重新加载页面才能再次触发。
我尝试通过以下方式使用 livequery() 插件,但似乎无法解决问题(obj 是包含所有行的 tbody 对象):
sortRows : function(obj) {
"use strict";
obj.livequery(function() {
$.each($(this), function() {
var thisTbody = $(this);
var thisUrl = thisTbody.attr('data-url');
thisTbody.tableDnD({
onDragClass: "trActive",
onDrop: function(thisTable, thisRow) {
var thisArray = [];
var thisRows = thisTbody.find('tr');
$(thisRows).each(function() {
thisArray.push($(this).attr('id').split('-')[1]);
});
$(thisRows).promise().done(function() {
$.post(thisUrl, { items : thisArray }, 'json');
});
}
});
});
});
}