0
我正在嘗試使用RP Niemeyer發佈的幾次敲除滑塊binderhalders。不幸的是,當試圖使用它時,我收到標題內的錯誤。Uncaught TypeError:屬性'min'對象#<Object>不是函數
(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];然而,通過改變我似乎無法正確返回值。我也嘗試更改滑塊選項的最小值和最大值,以便它們不是靜態設置的,但會引發完全不同的錯誤。任何幫助解決這個將不勝感激。
也許你可以基於這個小提琴重現:http://jsfiddle.net/rniemeyer/PgGL4/ –
我能弄清楚我的問題是,我以錯誤的方式設置我的viewmodel。在我做'food.criteriaMin = recipe.minValue; food.criteriaMax = recipe.maxValue;'而不是'food.criteriaMin(recipe.minValue); food.criteriaMax(recipe.maxValue);' –