使用cake php和java script

时间:2017-09-28 13:19:36

标签: javascript php cakephp-3.0

我试图使用带有cake 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 个答案:

答案 0 :(得分: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>"

                    );


                });