使用 Knockout-Kendo.js 动态启用/禁用剑道日期选择器 [英] Dynamically enable/disable kendo datepicker with Knockout-Kendo.js

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

问题描述

我正在尝试根据使用 Knockout-Kendo.js 的选择值启用/禁用剑道日期选择器.

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 动态启用/禁用剑道日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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