2015-11-11 161 views
1

我有一個腳本來刪除數據與Ajax。點擊刪除鏈接後,會出現一個確認框。隱藏對話框後隱藏塊

當我確認時,該框被隱藏,然後,包含已刪除數據的div也被隱藏。

我想包含刪除數據的div先被隱藏然後隱藏框。

// this div will be hidden 
<div id="remove-item{{entity.id}}" > 

    <a class="fa fa-trash-o fa-fw fa-2x remove_item" href data-entity-id="{{ entity.id }}"> 
       </a> 

</div> 
<script> 
    $(document).ready(function() { 
     $(".remove_item").click(function() { 
      var entityId = $(this).attr('data-entity-id'); // 
      var removeItem = '#remove-item-' + entityId; // the div 
      bootbox.dialog({ 
       title: '<i class="fa fa-exclamation-triangle" style="color: brown"></i> Confirm', 
       message: 'Delete ?', 
       className: 'my-class', 
       buttons: { 
        cancel:{ 
         className: 'btn btn-default', 
         label: 'Close' 
        }, 
        success: { 
         className: 'fa fa-trash-o btn btn-danger', 
         label: ' Delete', 
         callback: function(){ 

         $.ajax({ 
          type: 'POST', 
          dataType: 'json', 
          url: Routing.generate('travel_delete_ajax', {'id': entityId }), 
          success: function() { 
           $(removeItem).hide(); // hide the div 
          } 
        }); 
         } 
        } 
       } 
      }); 
      return false; 
     }); 
    }); 
</script> 

回答

1

隱藏在div 之前在打開的對話框:

$(".remove_item").click(function() { 
     var entityId = $(this).attr('data-entity-id'); 
     var removeItem = '#remove-item-' + entityId; 

     $(removeItem).hide(); // <-- here 

     bootbox.dialog({ 

     // <snip...> 

     }); 
    }); 
+0

是無法隱藏成功AJAX查詢後的股利? – hous