在noUISlider中格式化工具提示 [英] formatting the tooltip in noUISlider

查看:254
本文介绍了在noUISlider中格式化工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails项目中使用了noUISlider.

I am using the noUISlider in my rails project.

noUiSlider.create( slider, {
start: [3],
connect: 'lower',
step: 1,
range: {
  'min': 1,
  'max': 9
},
pips: { 
  mode: 'steps',
  density: 20
},
tooltips: true,
format: {
from: function(value) {
    return (parseInt(value)+" days");
  },
to: function(value) {
        return (parseInt(value)+" days");
    }
}
});

我希望它可以在工具提示中以天为单位.因此,我如上所述添加了format部分.但是start: 3将不再起作用.它从1开始.如果删除format,则start可以正常工作.

I want it to be a measure of days in the tooltip. So I added the format part as above. But start: 3 wont work anymore. It starts from 1 instead. If I remove the format, start works fine.

我尝试从js中删除format并编辑noUi-tooltip文本属性(附加"days"),但这也不起作用.

I tried removing the format and editing the noUi-tooltip text property from js (appending "days"), but that doesnt work either.

有帮助吗?

推荐答案

format中,from函数将值格式的字符串转换为数值.您需要将输入内容强制转换为一个数字:

In format, the from function converts the value from the formatted string to a numerical value. You'll want to cast your input to a number there:

format: {
    from: Number,
    to: function(value) {
        return (parseInt(value)+" days");
    }
}

这篇关于在noUISlider中格式化工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆