简体   繁体   中英

Knockout js jquery range slider && 2 inputs

I need a some help. I have a code http://jsfiddle.net/ZNvWR/19/ . I'm newbie in knockout, and I can't find any solution.

So, how to rewrite this code for getting working inputs (change values in inputs changes slider values)?

<div data-bind="jqSlider: percent, jqOptions: { min: 0, max: 100, range:true }"></div>
<hr/>
Percent: <input data-bind="value: percent()[0]" />
Percent: <input data-bind="value: percent()[1]" />

ko.bindingHandlers.jqSlider = {
  init: function(element, valueAccessor, allBindingsAccessor) {
    //initialize the control
    var options = allBindingsAccessor().jqOptions || {};
    $(element).slider(options);

    //handle the value changing in the UI
    ko.utils.registerEventHandler(element, "slide", function() {
        //would need to do some more work here, if you want to bind against non-observables
        var observable = valueAccessor();
        observable($(element).slider("values"));
    });

    //handle disposal (if KO removes by the template binding)
    ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
        $(element).slider("destroy");
    });
  },
  //handle the model value changing
  update: function(element, valueAccessor) {
    var value = ko.utils.unwrapObservable(valueAccessor());
    $(element).slider("values", value);   
  }
};

var viewModel = {
    percent: ko.observableArray([10,50])
};
ko.applyBindings(viewModel)

I just helped antoher SO user with a slider, it can be altered like this to do what you want

http://jsfiddle.net/N9uwx/3/

<input data-bind="value: min" /><input data-bind="value: max" /><div data-bind="slider: { min: min, max: max }, sliderOptions: {min: 0, max: 100, step: 1}"></div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM