簡體   English   中英

Knockout js jquery range slider && 2輸入

[英]Knockout js jquery range slider && 2 inputs

我需要一些幫助。 我有一個代碼http://jsfiddle.net/ZNvWR/19/ 我是淘汰賽的新手,我找不到任何解決方案。

那么,如何重寫此代碼以獲取工作輸入(更改輸入中的值會更改滑塊值)?

<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)

我只是用滑塊幫助了另一個SO用戶,它可以像這樣改變來做你想要的

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM