问题描述
我将再次通过询问基本知识来表达我的no昧.此后续问题与线程有关:从Apache访问JavaScript(Jquery)变量小门
Once again I'm gonna show my noobiness by asking about the basics. This follow-up question is related to thread: Accessing javascript (Jquery) variables from Apache Wicket
我开始使用AjaxSlider示例,我已经将值发送回给我,但是如何使用其他参数再次渲染滑块组件?我想更改可以分配给该AjaxSlider的最大值.对此是否有API?
I started to work with the AjaxSlider example, I have the value send back to me, but how do I render the slider component again with other parameters? I would like to change the maximum value that can be assigned to that AjaxSlider. Is there an api somewhere about this?
[我的目标是创建一个带有百分比(从0到100)的标签和两个滑块,您可以根据需要随意分配百分比.例如.让用户在男人和女人之间分配钱]这是我目前正在使用的代码:
[the object for me is to create a label with percentages (from 0 to 100) and two sliders with which you can distribute the percentage as you please. E.g. let the user distribute money among men and women] This is the code I'm working with currently:
add(new AjaxSlider("ajaxSlider1") {
private static final long serialVersionUID = 1L;
@Override
public void onValueChanged(AjaxRequestTarget target, int newValue) {
System.out.println("selected_value: "+newValue);
}
});
原始示例可在以下位置找到: AjaxSliderExample
The original example can be found here: AjaxSliderExample
感谢所有帮助,并感谢您阅读本文!
Appreciate all the help and thank you for reading this far!
推荐答案
您必须从onValueChanged(..)
方法中访问基础jqwicket的SliderBehavior
(例如,在AjaxSlider
中为SliderBehavior
创建吸气剂或保护它).之后,您可以像这样更改滑块的最大值:
You have to access the underlying jqwicket's SliderBehavior
from within the onValueChanged(..)
method (e.g. create a getter for the SliderBehavior
in the AjaxSlider
or make it protected). After this you can change the maximum value of the slider like this:
@Override
public void onValueChanged(AjaxRequestTarget target, int newValue) {
this.sliderBehavior.option(target, "'max'", "10");
}
通过这种方式,您可以操纵所有可用的滑块选项(请参阅jqwicket的SliderOptions
类或原始的JQuery UI Slider文档).
In this way you can manipulate all available slider options (see jqwicket's SliderOptions
class or original JQuery UI Slider documentation).
注意!您也可以继承jqwicket的预定义SliderWebMarkupContainer
以达到相同的结果.
Note! You can alternatively inherit jqwicket's predefined SliderWebMarkupContainer
to achieve the same result.
这篇关于使用JQWicket的AjaxSlider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!