在noUISlider中格式化工具提示 [英] formatting the tooltip in 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屋!