2014-09-12 58 views
0

我有一个表的一堆项目,我创建了一个函数来删除一行,但想用模式来确认用户实际上想删除一个行。查询有一个函数等待,直到用户点击是或取消

我删除功能如下:

var removeFootable_row = function() { 
    var $this, $currentFooTable, $currentTable, $currentRow; 
    $this = $(this); 
    $currentFooTable = $this.parents("table").data("footable"); 
    $currentTable = $this.parents("table"); 
    $currentRow = $this.parents("tr"); 

    $("#confirm-modal").modal("show"); 


    // I WANT TO PAUSE HERE AND ONLY CONTINUE IF THE USER CLICKS THE YES BUTTON 


    $currentRow.animate({opacity:0},{ 
     duration:150, 
     queue:false, 
     complete:function() { 
      setTimeout(function() { 
       $currentFooTable.removeRow($currentRow); 
      }, 250); 
     } 
    }); 
}; 

我读了一些关于承诺和延期,但我真的不知道该怎么办的最好的方法是这样的,任何想法?提前感谢您的帮助。

+1

将点击事件处理程序绑定到“是”按钮并将“animate”调用放在那里。 – 2014-09-12 19:02:42

+0

什么插件实现'模态'? – 2014-09-12 19:03:03

+0

我使用引导模式 – loriensleafs 2014-09-12 19:05:27

回答

1

另一个用户已经给你答案。你必须像这样分割你的功能。

// Global variable 
var $rowToDelete; 

function askUserConfirmation() { 
    var $this, $currentFooTable, $currentTable, $currentRow; 
    $this = $(this); 
    $currentFooTable = $this.parents("table").data("footable"); 
    $currentTable = $this.parents("table"); 
    $currentRow = $this.parents("tr"); 
    $rowToDelete = $currentRow; 
    $("#confirm-modal").modal("show"); 
} 

这将显示您的模态要求确认。现在,附加到“确定”按钮的功能,以实际删除该行。 (因为你没有张贴关于您的模式窗口,我将用户自己的ID任何代码,你将不得不改变他们对你的)

function removeFootableRow() { 
    $rowToDelete.animate({opacity:0},{ 
     duration:150, 
     queue:false, 
     complete:function() { 
      setTimeout(function() { 
       $currentFooTable.removeRow($currentRow); 
      }, 250); 
     } 
    }); 
} 

,并附加功能,以您的按钮。 HTML:

<!-- "Okay" button of your modal --> 
<input type="button" id="btnDeleteRow" /> 

使用jQuery将其附加:

$('#btnDeleteRow').off('click'); 
$('#btnDeleteRow').on('click', function() { 
    removeFootableRow(); 
}); 

就是这样。这将工作。

相关问题