如果只有一个结果可用于搜索,如何自动选择第一个条目 [英] How Do I Auto Select First Entry If Only One Result Is Available For Search

查看:69
本文介绍了如果只有一个结果可用于搜索,如何自动选择第一个条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





以下是我的相同代码。

我正在使用telerik控件。



我想要做的是,当我在组合中搜索时,如果搜索只有一个结果

那么组合应该自动选择它。目前我有选择它。

以下是我的片段....

Hi,

Below is my code for the same.
I am using a telerik controls.

What i want do is ,when i search in the combo ,if only one result exists for the search
then the combo should auto select it.Currently i have to select it.
below is my snippet....

<div class="form-combo" style="float: left">
                       @(Html.Kendo().ComboBoxFor(model => model.CardCode)//ComboBoxFor(model => model.CardCode)
                             .Name("CardCode")

                             .DataTextField("CustomerNameWithCode")
                             .DataValueField("CustomerId")
                             .Filter("contains")
                             .HtmlAttributes(new {style = "width:250px;"})
                             .AutoBind(true)
                             .MinLength(2)
                             .Events(ev =>
                             {
                                 ev.Select("SelectCustomer");
                                 ev.Change("ChangeCustomer");
                                 ev.Close("CloseCombo");

                             }

                             )
                             .DataSource(source =>
                             {
                                 source.Read(read =>
                                 {
                                     read.Action("GetAllCustomers", "Order").Data("additionalDataCustomer");
                                 });
                                 source.ServerFiltering(true);
                             })
                             )
                       <a style="cursor: pointer" onclick=" OpenCustomerPopUp() "><img src="~/Images/search.png" /></a>&nbsp;
                   </div>







function SelectCustomer() {
    document.getElementById('divAddNew').style.display = "block";
    //alert($('#CardCode').data('kendoComboBox').value());
    comboValue = $('#CardCode').data('kendoComboBox').value();
}

function ChangeCustomer() {


    comboValue = $('#CardCode').data('kendoComboBox').value();
    SaveCustomerToSessionForSelect();
}

function CloseCombo() {

    if ($('#CardCode').data('kendoComboBox').text() == 'No matching customers') {
        $('#CardCode').data('kendoComboBox').text('');
    }
}

function additionalDataCustomer() {
    try {
        //alert($('#CardCode').data('kendoComboBox').input.val());
        var str = $('#CardCode').data('kendoComboBox').input.val();//"Hello World!";
        var n = str.length;
        //alert(n);
        if (str.length >= 2) {
            return { searchValue: $('#CardCode').data('kendoComboBox').input.val() };
        }
        return { searchValue: "" };

    } catch (e) {
        alert(e);
    }

}





我可能会被困在我应该做的事情上我写的是为了做自动选择......

任何帮助都会受到赞赏.....



I am probably stuck as to what i should i write in order to do the auto select....
any help would be appreciated.....

推荐答案

(' 。#CardCode ')的数据(' kendoComboBox')值());
comboValue =
('#CardCode').data('kendoComboBox').value()); comboValue =


('#CardCode')。data('kendoComboBox')。value();
}

函数ChangeCustomer(){


comboValue =
('#CardCode').data('kendoComboBox').value(); } function ChangeCustomer() { comboValue =


('#CardCode')。数据( 'kendoComboBox')值()。
SaveCustomerToSessionForSelect();
}

函数CloseCombo(){

if(
('#CardCode').data('kendoComboBox').value(); SaveCustomerToSessionForSelect(); } function CloseCombo() { if (


这篇关于如果只有一个结果可用于搜索,如何自动选择第一个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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