开发者

Jquery Drag Sort order Call a function or API when change sort order (need help)

I have a pre-written code I want to change it. I don't understand what the problem is. I want to call an API when changing sort order of li. Here is the code:

  $(function() {
    $("#sortable").sortable({
    revert:true
    });

    $( "#dragable" ). draggable({
    connectToSortable: "#sortab开发者_C百科le",
    helper: "clone",
    revert:"invalid"
    });

       $("#sortable").bind( "sortstop", function (event, ui){

       var currentItem = ui.item;
       var currentPosition = $('#sortable li').index(currentItem) ;
       var callApi = true;
       var Id = currentItem[0].id;
       var html = Id.split('_')[1];
       if( currentPosition == sortOrder[html])
         {

        callApi=false;

            }
           sortOrder[html] = currentPosition;


          if(callApi)
          {

           buyer=new BHBuyer();
           buyer.updateSortOrder(html,currentPosition);
           }

    });


    $("ul, li").disableSelection();

    });

When I run this it gave me this error "Uncaught ReferenceError: sortOrder is not defined" Can any one help? Or is their any alternative way to fix this :S?


Initialize sortOrder with var sortOrder = new Object();. This have to be done on the global code, not inside the function.

Also change

if( currentPosition == sortOrder[html])

to

if (sortOrder[html] && currentPosition == sortOrder[html])

which will check if sortOrder[html] is defined before comparing

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜