Dojo slider: update value dynamically
I am building an application where the user browses certain objects by scrolling and zooming. To change the zoom level I have successfully implemented a "dijit.form.HorizontalSlider" object. Every time the user changes the position of the silder, I can catch the "onChange" call and do something with that.
However, the user can also zoom-in by double clicking inside the view zone, at which point the slider should change position automatically to reflect the new zoom level.
My question is the following: what function or method should I call in my jav开发者_开发问答ascript to update the position of a dojo silder ?
Here is the code that creates the silder object:
var zoomSlider = new dijit.form.HorizontalSlider({
name: "zoom_slider",
id: "zoom_slider",
value: 0,
minimum: 0,
maximum: 19,
discreteValues: 20,
intermediateChanges: false,
style: "width: 160px;",
onChange: function(value) {
brwsr.view.zoomTo(value);
}
},
"zoom_slider");
navbox_silder.appendChild(zoomSlider.domNode);
First you need to define an id property in your example's config object like id:'zoom_slider1'
to get a hold of the widget and then access it like this:
dijit.byId('zoom_slider1').attr('value',whateverthenewvalueis);
See Dijit Basics.
After DanMan's idea of adding an "id" field to the slider creation code, I dug into dojo's javascript files and found the appropriate undocumented internal method. This is it:
dijit.byId("zoom_slider")._setValueAttr(newvalue);
精彩评论