我有一个剑道UI下拉列表中我的看法:
$("#Instrument").kendoDropDownList({
dataTextField: "symbol",
dataValueField: "symbol",
dataSource: data,
index: 0
});
如何更改使用jQuery的它选择的值? 我试过了:
$("#Instrument").val(symbol);
但预期这是行不通的。
我有一个剑道UI下拉列表中我的看法:
$("#Instrument").kendoDropDownList({
dataTextField: "symbol",
dataValueField: "symbol",
dataSource: data,
index: 0
});
如何更改使用jQuery的它选择的值? 我试过了:
$("#Instrument").val(symbol);
但预期这是行不通的。
你必须使用剑道UI下拉列表select
(在文档的方法在这里 )。
基本上你应该:
// get a reference to the dropdown list
var dropdownlist = $("#Instrument").data("kendoDropDownList");
如果你知道索引可以使用:
// selects by index
dropdownlist.select(1);
如果不是,请使用:
// selects item if its text is equal to "test" using predicate function
dropdownlist.select(function(dataItem) {
return dataItem.symbol === "test";
});
例如的jsfiddle 这里
要做到这一点最简单的方法是:
$("#Instrument").data('kendoDropDownList').value("A value");
这里是的jsfiddle例子 。
由于这是与此问题上的搜索结果之一,我觉得这是值得一提的,你如何能与剑道()这一工作。DropDownListFor()为好。
一切都是一样的用OnaBai的职位,除了你如何选择基于关闭其文字和您选择的项目。
要做到这一点,你会换出dataItem.symbol的DataItem的。[DataTextFieldName。 无论模型字段时使用的.DataTextField()是什么,你会反对进行比较。
@(Html.Kendo().DropDownListFor(model => model.Status.StatusId)
.Name("Status.StatusId")
.DataTextField("StatusName")
.DataValueField("StatusId")
.BindTo(...)
)
//So that your ViewModel gets bound properly on the post, naming is a bit
//different and as such you need to replace the periods with underscores
var ddl = $('#Status_StatusId').data('kendoDropDownList');
ddl.select(function(dataItem) {
return dataItem.StatusName === "Active";
});
似乎有一个更简单的方法,至少在剑道UI v2015.2.624:
$('#myDropDownSelector').data('kendoDropDownList').search('Text value to find');
如果不是在下拉列表匹配,剑道出现在下拉菜单设置于未被选择的值,这是有道理的。
我不能让@刚的回答工作,但如果换成他的value
与search
,如上所述,我们的黄金。
这是可能的“原生”的价值选择:
dropdownlist.select(1);