开发者

passing jQuery ui sortable variable

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜