剑道组合框的问题 [英] Issue with kendo combobox

查看:76
本文介绍了剑道组合框的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的html中定义了kendocombox,如下所示

I have defined kendocombox in my html like below

<input  id="selFrameworkVersion" style="width: 210px" data-bind="kendoComboBox: { dataTextField: 'Name', dataValueField: 'Id', data:  $root.versionListByProductType, value:  $root.editFrameworkVersion, optionsCaption: 'Select Version...'  }" />

组合框可正确加载并设置值,但是当组合框未将焦点设置为列表中的适当项时.见下图

The combobox loads correctly and sets value but when it doesnt set focus to proper item in list. See image below

您可以看到值是5.5.1,但它设置为5.4,这是列表中的第一项. 我现在知道为什么会这样.在我的组合框中,您可以看到我的值设置为$ root.editFrameworkVersion.在我的视图模型中,我在该值上使用Subscribe事件.参见下面的代码

You can see value is 5.5.1 but it sets to 5.4 which is first item in list. I now know that why its happening. On my combobox you can see that i have value set as $root.editFrameworkVersion. In my view model i use subscribe event on that value. See code below

self.editFrameworkVersion.subscribe(function (value) {
        var combobox = $("#selFrameworkVersion").data("kendoComboBox");

        var callback = function (data) {

            self.editOnlyAlternativeVersions(self.versionListByProductType());

            combobox.select(function (dataItem) {
               return dataItem.Name === value;
            });
            self.editOnlyAlternativeVersions.remove(function (data) {

                return parseInt($("#selFrameworkVersion").attr('value')) === parseInt(data.Id()); 
            });


        };

        loadVersionListByProductType(self.editProductType().Id(), callback);

});

我使用这个订阅事件来做一些逻辑.在这种情况下,我要调用WCF服务,该服务会再次在该组合框中加载值,这就是为什么始终将其设置为第一个值.但这是我要求将该服务称为某种逻辑的要求.然后我在您已经在上面看到的订阅事件中添加了代码

I use this subscribe event to do some logic. In this event i am calling WCF service which loads value again in that combobox and thats why its always set to first value. But its required for me to call that service for some logic. Then i added code in that subscribe event which you already have seen above

combobox.select(function (dataItem) {
               return dataItem.Name === value;
            });

此代码可正确设置值,但前提是组合框失去焦点.我该怎么办?

This code sets the value correctly but only if combobox loses focus. What should i do?

推荐答案

尝试类似的方法 $(#selFrameworkVersion").attr("autofocus",true);

Try something like this $("#selFrameworkVersion").attr("autofocus",true);

这篇关于剑道组合框的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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