使用Knockout-Kendo.js动态启用/禁用kendo datepicker [英] Dynamically enable/disable kendo datepicker with Knockout-Kendo.js
问题描述
我正在尝试使用Knockout-Kendo.js基于选择的选定值来启用/禁用kendo日期选择器.
I'm trying to enable / disable a kendo datepicker based on the selected value of an select using Knockout-Kendo.js.
HTML:
<select data-bind="value: test">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input data-bind="kendoDatePicker: {value: date, enabled: test() == 2}" />
JS:
ko.applyBindings({
date: ko.observable(),
test: ko.observable(),
});
小提琴: http://jsfiddle.net/xTjqH/2/
最初它确实禁用了日期选择器,但是一旦选择了"2",它将不会启用它.
It does initially disable the datepicker, but it wont enable it once "2" is selected.
推荐答案
基于对kendo绑定中各个选项的依赖关系进行跟踪的方式,您需要用计算值来表示enabled
条件.否则,将立即对test() == 2
进行求值,而不会再次求值.
Based on the way that dependencies are tracked for the individual options in the kendo bindings, you would need to represent your enabled
condition with a computed. Otherwise, the test() == 2
is evaluated immediately and never again.
使用您的样本,您可以绑定到dateEnabled
之类的计算式:
With your sample, you could bind against a computed like dateEnabled
:
var viewModel = {
date: ko.observable(),
test: ko.observable(),
};
viewModel.dateEnabled = ko.computed(function() {
return viewModel.test() === "2";
});
示例: http://jsfiddle.net/rniemeyer/JaVKt/
这篇关于使用Knockout-Kendo.js动态启用/禁用kendo datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!