开发者

passing jQuery ui sortable variable

开发者 https://www.devze.com 2023-01-26 16:23 出处:网络
I was wondering how or if it\'s possible to pass a variable from \'start:\' to \'update:\' in the function below, without making the variable global?

I was wondering how or if it's possible to pass a variable from 'start:' to 'update:' in the function below, without making the variable global?

Thanks.

$('.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();


You could use jQuery's data in start like this:

ui.item.data('startPos', ui.item.index());

and then read it in update like this:

voteRank(entityId, ui.item.data('startPos'), endPos);

(edited so you can actually use it now)

0

精彩评论

暂无评论...
验证码 换一张
取 消