【发布时间】:2014-12-20 03:58:21
【问题描述】:
根据这个问题(和答案),我应该可以通过几种方式获得原始的开始位置和结束位置:
jQuery UI Sortable, how to determine current location and new location in update event?
$('#sortable').sortable({
start: function(e, ui) {
// creates a temporary attribute on the element with the old index
$(this).attr('data-previndex', ui.item.index());
},
update: function(e, ui) {
// gets the new and old index then removes the temporary attribute
var newIndex = ui.item.index();
var oldIndex = $(this).attr('data-previndex');
$(this).removeAttr('data-previndex');
}
});
或全部在更新事件中(首选):
$('#sortable').sortable({
update: function(e, ui) {
// ui.item.sortable is the model but it is not updated until after update
var oldIndex = ui.item.sortable.index;
// new Index because the ui.item is the node and the visual element has been reordered
var newIndex = ui.item.index();
}
});
但是,正如一些 cmets 中提到的那样,这对我不起作用。我或许应该提一下,我将 sortable 与 AngularJS 结合使用,特别是 the wrapper provided by AngularUI。对于第一个示例,我将$(this) 替换为$(e.target)。
关于为什么这不起作用以及如何获得所需结果的任何线索?
【问题讨论】:
标签: jquery angularjs jquery-ui angular-ui jquery-ui-sortable