2010-06-23 7 views
5

Estoy tratando de hacer cambios de categoría con Jquery & Php. No tengo ningún problema con eso. Mi problema es que cuando se llama al evento de actualización, devuelve 2 resultados. 1 resultado para Padre arrastrado, Un resultado para Dropped Parent. Quiero llamar solo la ID del padre abandonado. Aquí está mi script:El evento de actualización ordenable de Jquery puede llamarse solo una vez?

$("#gallery ul").sortable({ 
    connectWith: '.dropBox', 
    opacity: 0.35, 
    scroll: true, 
    scrollSensitivity: 100, 
    //handle: '.move', 
    helper: 'clone', 
    containment:'#gallery', 
    accept:'#gallery > .photo', 
    revert: true, 
    update: function(event, ui){ 
     params = 'c=' + $(this).attr('id') + '&id=' + ui.item.attr('id'); 

     $.ajax({ 
      type: 'POST', 
      url: 'processData.php', 
      data: params, 
      error:function(){ 
       alert("Error!"); 
      }, 
      success:function(data){ 
       $("#serverResponse").html(data); 
      } 
     }); 
    } 
}).disableSelection(); 

¿Me pueden ayudar chicos?

Respuesta

7

Use update, stop y receive eventos, por ejemplo

$(function() { 
    position_updated = false; //flag bit 

    $(".sortable").sortable({ 
     connectWith: ".sortable", 

     update: function(event, ui) { 
      position_updated = !ui.sender; //if no sender, set sortWithin flag to true 
     }, 

     stop: function(event, ui) { 
      if (position_updated) { 

       //code 

       position_updated = false; 
      } 
     }, 

     receive: function(event, ui) { 
      // code 
     } 

    }).disableSelection(); 
}); 
1

Usted debe tratar de jugar con los diferentes eventos sortable

  • inicio
  • tipo
  • cambio
  • beforeStop
  • parada
  • actualización
  • reciben
  • eliminar
  • sobre
  • cabo
  • activar
  • desactivar

Estoy bastante seguro de que uno of'em será su respuesta.

Fuente: http://jqueryui.com/demos/sortable/#event-change

3

ui.sender sólo existe en la segunda devolución de llamada.

$(".sortable").sortable({ 
    connectWith: ".sortable", 
    update: function (evt, ui) { 

     // just ignore the second callback 
     if(ui.sender == null){ 

      // call ajax here 

     } 


    }, 
    receive: function (evt, ui) { 

     // called after the first 'update' 
     // and before the second 'update' 
     // ui.sender is always exists here 

    } 

}).disableSelection(); 
+0

+1 excelente. Esto fue como un rasguño de cabeza. Gracias –

0

a hacer esto:

update: function(event, ui) { 
      if(ui.sender) { 
      // Your actual code 
      } 
     }, 
Cuestiones relacionadas