Bind slider max option to observable value
Hello and happy new year:
I have a problem to bind the max option of my jquery slider to an ko.observable value.
I´ve got the following error massage maybe you can help me.
Unable to process binding "slider: function (){return { min:10,max:max,step:10} }"
Message: cannot call methods on slider prior to initialization; attempted to call method 'max'
This is my code:
- <div data-role="content">
-
- <div>
- <input data-bind="textinput: max"></input>
- </div>
- <div>
- <span data-bind="text: value1"></span>
- </div>
-
- <div>
- <label for="Range1Slider">GRP:</label>
- <input type="range" name="Range1Slider" data-bind="slider: { min: 10, max: max, step: 10 }" />
- </div>
-
-
- </div>
-
-
- <script type="text/javascript">
-
- function ViewModel() {
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- //KnockoutJS Form Variablen
- //////////////////////////////////////////////////////////////////////////////////////////
-
- var self = this;
-
- self.max = ko.observable(200);
- self.value1 = ko.observable(20);
- }
-
-
- ko.bindingHandlers.slider = {
- init: function (element, valueAccessor, allBindings, ViewModel, bindingContext) {
- var options = ko.unwrap(valueAccessor()),
- valueObservable = allBindings().value;
-
- // to your init work for the slider-plugin
- // maybe the following ?
- $(element).slider('max', options.max());
-
- // logic for element-disposal should be implemented
-
- },
- update: function (element, valueAccessor, allBindings, ViewModel, bindingContext) {
- var options = ko.unwrap(valueAccessor()),
- valueObservable = allBindings().value;
-
- // this will be called if the value-binding changed or the max-observable changed
- // update the max-option
- // maybe the following ?
- $(element).slider('max', options.max());
- }
- }
-
- ko.applyBindings(ViewModel);
- </script>