简体   繁体   English

隐藏引导程序下拉菜单时如何放置事件?

[英]How do I put an event when the bootstrap dropdown is hidden?

I have the following 2 functions: filterbuttons and getTableData. 我有以下2个功能: filterbuttonsgetTableData.

The first function decides whether the call to counter should or should not appear on the table rows. 第一个函数决定对计数器的调用是否应该出现在表行中。 The second function builds the table data based on retrieved information from database. 第二个功能基于从数据库中检索到的信息来构建表数据。

function filterButtons(status) {
    $append = "";
    if (status == "PENDING") {
        $append = "<td class='dropdown'><a id='call' class='btn btn-primary actionButton' data-toggle='dropdown'> Call to Counter </a><a class='btn btn-danger cancelbtn' > Cancel </a></td>";
    } else if (status== "SERVING") {
        $append = "<td><a class='btn btn-danger cancelbtn' > Cancel </a><a class='btn btn-success donebtn'>Done</a></td>";
    }
        return $append;
    }

    function getTableData() {
        $.ajax({
            url: 'inc/php/fetch_data.php',
            type: 'POST',
            async: false,
            data: 'data=gettabledata',
            datatype: "text",
            success: function (data) {
                console.log(1);
                $('.table-hover tbody').empty();    //refresh the table data
                dataArray = JSON.parse(data);           //covert data from server to js array
                $.each(dataArray, function (key, value) {
                    $('.table-hover tbody').append("<tr><td>" + value[0] + "</td><td><font size='3px'>" + value[1] + "</font></td><td><font size='3px'><b>" + value[2] + "</b></font></td><td><font size='3px'>" + value[3] + "</font></td><td><font size='3px'>" + value[4] + "</font></td><td><font size='3px'>"+value[5]+"</font></td>"+filterButtons(value[2])+"</tr>");
                }); 

                $(".actionButton").click(function () {  
                    //move dropdown menu
                    $(this).after($dropdown);

                   // clearInterval(counter);
                   // clearInterval(table);
                    // $(".actionButton").click(function(){
                    //     table = setInterval(getTableData,150);
                    // });
                });

                $(".dropdown").on('hide.bs.dropdown', function(){
                        console.log("hide method called");
                    });


                $(".cancelbtn").click(function (){
                    var id = $(this).closest("tr").children().first().html();
                    if(confirm("Are you sure you want to cancel the transaction?")){


                        $.ajax({
                            url: 'inc/php/fetch_data.php',
                            type:'POST',
                            async: false,
                            data:'data=canceltrans&id='+id,
                            datatype:'text',
                            success: function(data){
                                if(data=="1"){
                                    console.log("Cancel Successful!");
                                }
                            }
                        });
                    }
                });

                $(".donebtn").click(function(){
                    var id = $(this).closest("tr").children().first().html();

                    $.ajax({
                        url: 'inc/php/fetch_data.php',
                        type: 'POST',
                        async: false,
                        data: 'data=completetrans&id='+id,
                        datatype:'text',
                        success: function(data){
                            if (data=="1"){
                                console.log("Transaction Completed");
                                location.reload();
                            }
                        }
                    });
                });
            }
        });  

        $.ajax({
            url:'inc/php/fetch_data.php',
            type: "POST",
            async: false,
            data: "data=getavailcounter",
            datatype: "text",
            success: function (data){
                $dropdown.empty();
                dataArray = JSON.parse(data);
                $dropdown.append('<li><a class="Label">Select Counter:</a></li>');
                $.each(dataArray, function (key,value){
                    $dropdown.append('<li><a class="counterLink" role="menu">'+value+'</a></li>');
                });

                //CODE FOR CLICK FUNCTION on select counter from dropdown
                $(".counterLink").click(function (){
                    console.log("Counter CLicked!");
                    table = setInterval(getTableData,150);
                    var counter = $(this).html();
                    var id = $(this).closest("tr").children().first().html();
                    $.ajax({
                        url: 'inc/php/fetch_data.php',
                        type: 'POST',
                        async: false, 
                        data: "data=calltrans&id="+id+"&counter="+counter,
                        datatype:"text",
                        success: function (data){
                            if(data=="1"){
                                console.log("Call Successful!");
                            }
                            else{
                                console.log("Unsuccessful!");
                            }
                            location.reload();
                        }

                    });
                });
            }
        });   
    }

I've read some info online on how to do this and I got the following code to put the function to be executed when the dropdown is closed: 我已经在线阅读了一些有关如何执行此操作的信息,并获得了以下代码来放置要在下拉列表关闭时执行的功能:

$(".dropdown").on('hide.bs.dropdown', function(){
    console.log("hide method called");
});

I added that code to the function getTableData just right after the click function for the button with dropdown. 我在带有下拉按钮的点击功能之后,立即将代码添加到了功能getTableData中。 When I tried it, nothing comes up on my console so it must not be reaching that portion of my code. 当我尝试它时,控制台上什么都没有出现,因此它一定不能到达我的代码的那部分。 Can anybody please tell me why? 有人可以告诉我为什么吗?

Sorry for the dumb question. 很抱歉这个愚蠢的问题。 I just realized that it was a problem with the bootstrap imports. 我只是意识到引导导入是一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在引导程序上触发下拉按钮模糊/关闭事件? - How do I trigger a dropdown button blur / close event on bootstrap? 如何使用下拉列表onchange事件将颜色放入画布的矩形中 - How do I put color into a rectangle in a canvas using a dropdown list onchange event Bootstrap 4:单击下拉项时如何关闭下拉菜单? - Bootstrap 4: How Do I Close a dropdown-menu when a dropdown-item is clicked? Bootstrap Navbar-当前面的下拉列表折叠时,如何确保下拉列表的顶部在视口中? - Bootstrap Navbar - How do I ensure that the top of a dropdown is in the viewport when the preceding dropdown collapses? 如何将 SAFEARRAY(字节数组)放入 HTML 隐藏字段 - How do I put SAFEARRAY (array of bytes) to HTML Hidden field Dropdown Bootstrap显示和隐藏事件不等待CSS过渡 - Dropdown Bootstrap shown and hidden event not wait for CSS Transition 面板隐藏的Bootstrap下拉菜单 - Bootstrap dropdown hidden by panel 如何将jquery multiselect下拉列表的选定值放入隐藏元素的ID中 - How can I put selected value of jquery multiselect dropdown into a hidden element's id 如何在 react-bootstrap 中实现溢出隐藏? - How do I implement overflow-hidden in react-bootstrap? 单击引导程序下拉链接时,如何获得灰色的网页覆盖? - How do I get grey webpage overlay when clicking on bootstrap dropdown link?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM