使用Knockout-Kendo.js动态启用/禁用kendo datepicker [英] Dynamically enable/disable kendo datepicker with Knockout-Kendo.js

查看:139
本文介绍了使用Knockout-Kendo.js动态启用/禁用kendo datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆