未捕获的TypeError:对象#<object>的属性'min'不是函数</object>

时间:2013-11-25 16:09:42

标签: jquery-ui knockout.js slider

我正在尝试使用RP Niemeyer已发布几次的淘汰滑块活页夹。不幸的是,在尝试使用它时,我在标题中收到错误。

(function($){

ko.bindingHandlers.slider = {
    init: function (element, valueAccessor, allBindingsAccessor) {
        var options = allBindingsAccessor().sliderOptions || {};
        var sliderValues = ko.utils.unwrapObservable(valueAccessor());

        if(sliderValues.min !== undefined) {
            options.range = true;
        }

        options.slide = function(e, ui) {
            if(sliderValues.min) {
                // Errors here
                sliderValues.min(ui.values[0]);
                sliderValues.max(ui.values[1]);
            } else {
                sliderValues.value(ui.value);
            }
        };

        ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
            $(element).slider("destroy");
        });

        $(element).slider(options);
    },
    update: function (element, valueAccessor) {
        var sliderValues = ko.toJS(valueAccessor());
        if(sliderValues.min !== undefined) {
            $(element).slider("values", [sliderValues.min, sliderValues.max]);
        } else {
            $(element).slider("value", sliderValues.value);
        }
    }
};

this.range = {
    'cook': function(kitchen, name, label, recipe){

        var food = new this.viewModel(kitchen);
        food.name = name;
        food.label = label;
        food.total(recipe.numberOfResults);
        food.criteriaMin = recipe.minValue;
        food.criteriaMax = recipe.maxValue;

        return food;
    },
    'viewModel': function(kitchen){
        var self = this;

        this.name = '';
        this.label = '';

        this.total = window.ko.observable();

        this.criteriaMin = ko.observable(0);
        this.criteriaMax = ko.observable(100);

        this.loading = window.ko.observable(false);
        this.template = '';

        this.getSelection = function(){
            return null;
        };

        this.setSelection = function(){

        };
    },
    'template': '<th class="idc-td-criteria" scope="row" data-bind="text:label"></th>' +
        '<td class="idc-td-value idc-td-slider">' +
        '   <label for="AmountMin"  class="hiddenText">Amount Min</label>' +
        '   <input type="text" data-default="0" data-maxdecimal="2" class="idc-textinput idc-sliderinput" maxlength="6" data-bind="value: criteriaMin || \'0.00\'">' +
        '   <span class="slider" data-bind="slider: { min: criteriaMin, max: criteriaMax }, sliderOptions: {min: 0, max: 100, step: 1}"></span>' +
        '   <label for="AmountMax"  class="hiddenText">Amount Max</label>' +
        '   <input type="text" data-default="10" data-maxdecimal="2" class="idc-textinput idc-sliderinput" maxlength="6" data-bind="value: criteriaMax || \'10.00\'">' +
        '</td>' +
        '<td class="idc-td-results" data-bind="text:total"></td>' +
        '<td class="idc-td-remove">' +
        '   <a href="#">' +
        '       <img src="images/column_delete.png" alt="Delete criteria [criteria name]" role="button"  />' +
        '   </a>' +
        '</td>'
    };
}).call(window.idmsScreener.chefs, jQuery);

我试图将它从sliderValues.min()更改为sliderValues.min = ui.values [0];但是通过改变我似乎无法正确地获得值。我还尝试更改滑块选项的最小值和最大值,以便它们不会静态设置但会引发完全不同的错误。任何帮助解决这个问题都将非常感激。

1 个答案:

答案 0 :(得分:0)

能够解决这个问题。确定我正确设置了我的最小和最大标准。我正在使用等于可观察的等号来进行赋值。