Kendo UI MVC DropDownList 过滤焦点

Kendo UI MVC DropDownList Focus For Filtering

我正在使用 MVC Razor 和 Telerik Kendo MVC。我有一个 dropdownlst,我想将其自动设置为焦点,以便用户可以立即开始键入和过滤所需的值。 ddl 是:

@(Html.Kendo().DropDownList()
    .Name("ddlLocations")
    .Filter("contains")
    .BindTo(Model.Locations)
    .DataTextField("Text")
    .DataValueField("Value")
    .Events(events => events.Change("onChange"))
    .HtmlAttributes(new { style = "width:100%" })
    .Value(Model.Exception.LocationIDCouponTypeStatus)
)

我在 ASP.NET WebForms 中有一个类似的项目,我在 Javascript 中所做的是:

 var comboBox = $find("<%=ddl.ClientID %>");
 comboBox._inputDomElement.select();

这侧重于告诉它在用户开始键入时开始过滤的控件部分。它似乎没有转换为 MVC 版本。

var comboBox = $("#ddlLocations").data("kendoDropDownList");
comboBox._inputDomElement.select();

有什么想法吗?提前致谢。

您需要先打开下拉列表:

.Events(p => p.DataBound("function(e){ this.open(); this.filterInput.focus(); }"))

备选方案:

$(function(){
    var dd = $("#ddlLocations").data("kendoDropDownList");
    dd.open();
    dd.filterInput.focus();
});

.Events(p => p.DataBound("function(e){ setTimeout(function(){ this.open(); this.filterInput.focus(); }, 500); }"))

比这容易得多,Kendo 已经有一个 focus() 函数,只需执行 comboBox.focus()