Delete duplicate data

0

I have the following code created in javascript, which generates a url in the browser, but the problem is that each filter duplicates the data, that is, it reloads the previously selected filters, causing the url to fill with garbage, someone who can help me, I thank you very much.

function GetFiltersForProducts()
{
    var filters = [];

    $("#estuyo-facets .facet_container").each(function(i, e){         

        var filter = $(e).find(".facet_title");

        var filter_field = filter.attr("id");
        var filter_values = [];

        filter.parent().find(".element_container input[type='checkbox']:checked").each(function(i, e){

            if($(e).attr('name') != 'Zapatos')
            {
                    var filter_unRepeat = filter_values.push({'values' : $(e).val(), 'name': $(e).attr('name')});

            }

        });

        var filter_shoes = filters.push({ 'filter_field': filter_field, 'filter_values': filter_values });
    });

    return filters;
};
    
asked by juan vargas 20.01.2017 в 22:45
source

1 answer

0

This was the code that I had to implement to solve the problem. This function simply traverses the string and removes those characters or words I find repeated, and then sends the string to the URL.

I had not been able to publish it because I had not had the time or the space.

function RewriteUrl(url_rewrite) {
    var base_url = '';
    var number_page = parseInt($("#page_current").val()) + parseInt(1);
    var page = '&page=';

    if (url_rewrite != "#?page=1") {
        for (var i = 0; i < window.location.href.length; i++) {
            var l = window.location.href[i];

            if (l == "#") {
                break;
            } else {
                base_url += l;
            }
        }

        var url_array = (base_url + url_rewrite).split("?");
        var url_params = '';
        var arraySinDuplicados = [];

        if (url_array.length > 1) {
            var arrayOriginal = url_array[1].split("&");
            var arraySinDuplicados = arrayOriginal.filter(function(elem, pos) {
                return arrayOriginal.indexOf(elem) == pos;
            });

            url_params = '?' + arraySinDuplicados;

            if (number_page != 1) {

                var url_page = '';
                var url_page_sin_duplicados = [];
                var url_params = '?' + arraySinDuplicados;

                if (url_array.length > 1) {
                    var arrayOriginal = url_array[1].split("&");
                    var url_page_sin_duplicados = arrayOriginal.filter(function(elem, pos) {
                        return arrayOriginal.indexOf(elem) == pos;
                    });

                    url_params = '?' + url_page_sin_duplicados.join('&').replace(/[\d]/, number_page);
                    window.history.pushState({}, document.title, url_array[0] + url_params);
                }

            }

            if (number_page == 1) {
                url_params = '?' + arraySinDuplicados.join('&').replace(/[\d]/, number_page);
                window.history.pushState({}, document.title, url_array[0] + url_params);
            }
        }
    }
};
    
answered by 03.02.2017 в 20:14