简体   繁体   English

从引导范围滑块获取单独的值

[英]Get seperate values form the bootstrap range-slider

I'm trying to get the min and max value from a bootstrap range slider. 我正在尝试从bootstrap范围滑块获取最小值和最大值。 I want both values to use in an array. 我希望两个值都可以在数组中使用。

I have this function : 我有这个function

var slider = new Slider('#periodslider', {
     formatter: function(value) {
         var period = ['1-1/Jaar-2', '1-6/Jaar-2', '31-12/Jaar-2', '1-1/Jaar-1', '1-6/Jaar-1', '31-12/Jaar-1'];
         //return period[value - 1];
     }
});

What I want is to use the min value to label the value to a label within the period array. 我想要的是使用最小值将值标记为period数组内的标签。 Same goes for the max value. 最大值也一样。

With a normal slider I use this function : 使用普通的滑块,我可以使用以下function

var slider = new Slider("#frequencyslider", {
    //tooltip: 'always',
    formatter: function(value) {
        var frequency = ['Maand', 'Kwartaal', 'Jaar'];
        return frequency[value - 1];
    }
});

This doesn't work for what I want becaus with a range slider it outputs the values as: 1:5 这对于我想要的不起作用,因为使用范围滑块它将值输出为: 1:5

I found the solution: the docs of bootstrap-slider.js pointed out that in the case of a range slider, the value type isn't float but an array . 我找到了解决方案: bootstrap-slider.js的文档指出,在使用范围滑块的情况下,值类型不是float而是array

To get what I wanted, I made the function like this: 为了得到我想要的东西,我做了这样的功能:

var slider = new Slider('#periodslider', {
 formatter: function(value) {
     var period = ['1-2013', '7-2013', '1-2014', '7-2014', '1-2015'];
     return period[value[0]] + " tot " + period[value[1]];
     }
});

This works perfectly! 这样完美!

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

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