当类型为 'single' 时如何在 IonRangeSlider 中获取和获取值

How to get from and to values in IonRangeSlider when type is 'single'

我正在使用 IonRangeSlider,其中有 3 个自定义值:

["Value1","Value2","Value3"] 

并且类型是single

现在我想要的是,我想以某种方式检测 from 和 to 值如果我从 Value1 切换到 Value2 那么我希望它们的值都在 2 个不同的变量中作为我有一些基于 from 和 to 值的计算。但是我能做的就是可以获得像 Value1.

这样的 From 值

下面是我的代码。

$('#Strategy').ionRangeSlider({
      type: 'single',
      grid: true,
      values: ["Value1","Value2","Value3"],
      onFinish: function (obj) {                
          alert(obj.from_value);
      }
});

Working fiddle.

single 的情况下 to 总是 null 如果你查看 onFinish 回调的响应参数,也是传递数组的第一项将永远是 to 所以你可以得到两个 from/to 像 :

var maintenanceStrategyItems = ["Preventive","Optimal","Corrective"];
var old_value=maintenanceStrategyItems[0];

$('#Strategy').ionRangeSlider({
  type: 'single',
  grid: true,
  values: maintenanceStrategyItems,
  onChange: function (data) {
    console.log(old_value, data.from_value);
    old_value=data.from_value;
  }
});

希望对您有所帮助。

var maintenanceStrategyItems = ["Preventive","Optimal","Corrective"];
var old_value=maintenanceStrategyItems[0];

$('#Strategy').ionRangeSlider({
  type: 'single',
  grid: true,
  values: maintenanceStrategyItems,
  onChange: function (data) {
    console.log(old_value, data.from_value);
    old_value=data.from_value;
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<link href="http://ionden.com/a/plugins/ion.rangeSlider/static/css/ion.rangeSlider.skinFlat.css" rel="stylesheet"/>
<link href="http://ionden.com/a/plugins/ion.rangeSlider/static/css/ion.rangeSlider.css" rel="stylesheet"/>
<script src="http://ionden.com/a/plugins/ion.rangeSlider/static/js/ion-rangeSlider/ion.rangeSlider.js"></script>
<input type="text" id="Strategy" value="" />