简体   繁体   English

如何防止在表中添加多次,一旦使用Jquery迫使它多次双击表行?

[英]How to prevent appending multiple times in the table, Once It forcing to double click multiple times the table row using Jquery?

I have module appending the result of response to the other table. 我有模块将响应结果附加到另一个表。 looking forward I found a solution in my module. 期待我在我的模块中找到了解决方案。 however I found problem on that i will give to you guys the scenario what the problem it does. 但是我发现了问题,我会给你们解决方案问题所在。

First Scenario : User will choose what condiment he wanted to click, Looking forward Ex. 第一种情况 :用户将选择他想单击的调味品,向前看。 User 1 choose the Second table row, the Condiments *LG FRIES . 用户1选择第二个表行,即调味品* LG FRIES

第一个场景

Second Scenario : In the first scenario user choose the *LG FRIES , as you can see here modal will open and the result of response will append to the table B. 第二种情况 :在第一种情况下,用户选择* LG FRIES ,如您所见,模态将打开,响应结果将附加到表B中。

第二场景

Third Scenario : Well First and Second scenario look works and good, but here I will show you, how does appending will multiply in the table once i force double click the table row of *LG FRIES . 第三种情况 :第一种和第二种情况看起来不错,但是在这里,我将向您展示,一旦我强制双击* LG FRIES的表行,追加将如何在表中相乘。

第三场景

So now i will let you show my codes. 所以现在我让您展示我的代码。

This is my function for getting the result of clicking the of table row then the result will append to the table B. 这是我获取单击表行的结果的功能,然后结果将附加到表B。

$('table#noun_chaining_order').on('click','tr.editCondiments',function(e){



    var allow_to_open_condiments_conditional =  $(this).closest("tr").find(".allow_to_open_condiments_conditional").text();


    if(allow_to_open_condiments_conditional == 'Yes') {

        $('.conditional_table_hidden_noun').hide();

        $('.conditional_table_hidden_condiments').show();

        $('table#noun_chaining_order tr').removeClass('selected');

        $(this).addClass('selected');



        var find_each_id_condiments = $(this).find('td.condi_section_id').text();
         $("table#customer_table_update_chain_order tbody").html('');

        $('#customer_modal_update_chain_order').modal('show');

         $.ajax({
          url:'/get_each_id_section_condiments',
          type:'get',
          data:{find_each_id_condiments:find_each_id_condiments},
          success:function(response){

            var get_each_section = response[0].condiments_table;


            $.each(get_each_section, function (index, el) {

               var stringify = jQuery.parseJSON(JSON.stringify(el));


              var cat_condi_screen_name = stringify['cat_condi_screen_name'];
              var cat_condi_price = stringify['cat_condi_price'];
              var cat_condi_image = stringify['cat_condi_image'];
              var image = '<img src=/storage/' + cat_condi_image + ' class="responsive-img" style="width:100px;">';

              // $('#edit_chainingBuild').append("<tr class='clickable-row'><td>" + Qty + "</td><td class='clickable-row-condiments'>" + Condiments + "</td><td>" + Price + "</td><td style='display:none;' data-attribute-chain-id="+menu_builder_details_id +" class='data-attribute-chain-id'>"+menu_builder_details_id+"</td></tr>");

              $('table#customer_table_update_chain_order tbody').append("<tr class='edit_condimentsClicked' style='font-size:14px; border:none;'><td class='edit_condimentsScreenNameClicked'>" + cat_condi_screen_name + "</td><td class='edit_condimentsScreenPriced'>" + cat_condi_price + "</td><td>"+image+"</td></tr>");

            });



          },
          error:function(response){
            console.log(response);
          }
        });

    }
    else
    {

    }

});

So the question will be, How to stop appending multiple times once I force double click the table row? 因此,问题将是,一旦我强制双击表格行,如何停止多次追加?

I see simple solutions here. 我在这里看到简单的解决方案。

  1. When you appending cart item, you can add that item ID from database to the element. 追加购物车商品时,可以将商品ID从数据库添加到元素中。 And before appending check if an item from response doesn't exist in BODY. 并且在附加之前检查BODY中是否没有来自响应的项目​​。
  2. Another solution will be just after you click append - hide that CTA (button)to prevent it from another click. 单击附加后,另一个解决方案是-隐藏该号召性用语(按钮)以防止再次单击它。
  3. Check your database for multiple records. 检查数据库中是否有多个记录。

Anyways, please check when you do ajax request? 无论如何,请检查何时执行ajax请求? after click? 点击后?

Have you tried to debug your code with breakpoints? 您是否尝试过使用断点调试代码? or console? 或控制台?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM