Add tip text dynamically to a slider

对着背影说爱祢 提交于 2019-12-12 02:06:51

问题


In my project, I am trying to add the tip text (config) dynamically to a slider. How to do that? I need to add it dynamically because I am generating the array of variables in a "Controller", which holds the text for each value of the slider (for tip text).

var slider = Ext.getCmp('slider')
slider.setTipText(arrayOfVariables)    //What should I do here instead?

There is no such method like setTipText in docs. What should I use then?

EDIT:

{
        xtype:'slider',
        animate: false,
        //plugins: [Ext.create('App.view.SliderOverride')],
        cls: 'sliderStyle',
        width: "80%",
        id: 'slider',
        value: 36/2, //must be current month
        //increment: 10,
        minValue: 1,
        maxValue: 36,
        useTips: true,          
        tipText: function(thumb){
            alert("hello");
            App.getController('TaskController')._arrMonthView[thumb.value].month;
        },
},

回答1:


tipText requires a function config so you can add a function that will use your variables from controller;

Ext.create('Ext.slider.Multi', {
    ....
     tipText: function(){
          return App.getController('your controller').yourVariable
     },
    .....
});

This is added on the creation of the slider so you don't need to modify it , just your variables in controller. So you don't need to re set the tip text function.




回答2:


I solved this issue by using getText method of Ext.slider.Tip.

Used to create the text that appears in the Tip's body. By default this just returns the value of the Slider Thumb that the Tip is attached to. Override to customize.

For example in which situation it can be used, you have a look at this link



来源:https://stackoverflow.com/questions/15338960/add-tip-text-dynamically-to-a-slider

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