How to update values in Jquery range slider

若如初见. 提交于 2021-01-29 11:52:00

问题


I'm using jquery range slider. I have an ajax call and I set the slider values in that ajax call. The code is as follows:

$.ajax({
        type: "POST",
        url: '/api/get-prices/',
        data: JSON.stringify(filters),
        contentType: "application/json",
        beforeSend: function (xhr, settings) {
            let csrftoken = getCookie('csrftoken');
            if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrftoken);
            }
        },
        success: function (response) {
            let min_price = parseInt(_.min(response['prices']));
            let max_price = parseInt(_.max(response['prices']));
            let price_slider = $("#vehicles #price-slider");

            $.HSCore.components.HSSlider.init(price_slider);
            price_slider.slider( "values", 0", min_price );
            price_slider.slider( "values", 1, max_price );
            price_slider.attr('data-min', min_price);
            price_slider.attr('data-max', max_price);
            price_slider.attr('data-default', min_price + ", " + max_price);
            min_price_wrapper.html(addDotAsThousandSeparator(min_price) + "€");
            max_price_wrapper.html(addDotAsThousandSeparator(max_price) + "€");
            $.HSCore.components.HSSlider.init(price_slider);
        },
        error: function () {

        }
    })

When I do that in success function the slider is rendered fine and the labels which I see are fine. min_price is 12690 and max_price is 19711 and the slider which is rendered is as follows:

Everything seems fine. But when I start to slide those values are not correct. The start label is 30 instead of 12690 and the stop label is 35000 instead of 19711.

Any idea what am I doing wrong?

来源:https://stackoverflow.com/questions/53369909/how-to-update-values-in-jquery-range-slider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!