2017-09-28 26 views
0

我想過濾使用java腳本和蛋糕php框架工作追加的表。 和下面的代碼是添加這個表,當我點擊添加新的雜誌,但問題是,它添加了以前已添加的雙行。所以我需要過濾添加的行來刪除重複的行。用蛋糕php和java腳本過濾重複行

/// function to show magazines data table 
    $('#add_researches_button').click(function() { 
     $("input[name='bstock_researchs_id[]']:checked").each(function (i) { 
      val[i] = $(this).val(); 

     }); 
     $.ajax({ 
      type: "POST", 
      url: '../BstockIn/getResearchesIds/' + val, 
      dataType: "json", 
      success: function (data) { 
       $('#researches').css('display', 'block'); 

       var res = $.parseJSON(data); 

       var CountResearches = 0; 

       jQuery.each(res, function (index, value) { 

        CountResearches++; 

        $("#researches").append("<tr><td>" 
          + value.research_serial + 
          "</td><td>" 
          + value.research_release_date + 
          "</td><td>" 
          + value.research_release_hejry_date + 
          "</td><td>" 
          + value.research_pages + 
          "</td><td>" 
          + value.research_copies + 
          "</td></tr>" 

          ); 


       }); 

回答

1
/// function to show magazines data table 
$('#add_researches_button').click(function() { 
     $("input[name='bstock_researchs_id[]']:checked").each(function(i) { 
     val[i] = $(this).val(); 

     }); 
     $.ajax({ 
      type: "POST", 
      url: '../BstockIn/getResearchesIds/' + val, 
      dataType: "json", 
      success: function(data) { 
       $('#researches').css('display', 'block'); 

       var res = $.parseJSON(data); 

       var CountResearches = 0; 

       jQuery.each(res, function(index, value) { 

        CountResearches++; 
        if ($("#researches tr[data-id='" + value.research_serial + "']").length == 0) 
        $("#researches").append("<tr data-id='" + value.research_serial + "'><td>" + 
         value.research_serial + 
         "</td><td>" + 
         value.research_release_date + 
         "</td><td>" + 
         value.research_release_hejry_date + 
         "</td><td>" + 
         value.research_pages + 
         "</td><td>" + 
         value.research_copies + 
         "</td></tr>" 

        ); 


       }); 
+0

謝謝你,它的工作! –