我想知道如何或者是否可以在下面的函数中将变量从'start:'传递给'update:'而不使变量成为全局变量?
感谢。
$('.type').sortable({
placeholder: 'entityHighlight',
cancel: '.disabled',
opacity: 0.9,
revert: true,
scroll: true,
start:function(event,ui) {
startPos = ui.item.index();
},
update: function(event,ui) {
var endPos = ui.item.index();
var entityId = ui.item.attr('id');
voteRank(entityId,startPos,endPos);
}
}).disableSelection();
答案 0 :(得分:4)
您可以在start
中使用jQuery的data,如下所示:
ui.item.data('startPos', ui.item.index());
然后在update
中阅读,如下所示:
voteRank(entityId, ui.item.data('startPos'), endPos);
(已编辑,因此您现在可以实际使用它)