![](/img/trans.png)
[英]Selected kendo Dropdownlist value getting reset to previous selected value while performing batch operation in kendo ui grid
[英]Change selected value of kendo ui dropdownlist
我的视图中有一个kendo ui下拉列表 :
$("#Instrument").kendoDropDownList({
dataTextField: "symbol",
dataValueField: "symbol",
dataSource: data,
index: 0
});
如何使用jQuery更改它的选定值? 我试过了:
$("#Instrument").val(symbol);
但它没有按预期工作。
您必须使用Kendo UI DropDownList 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示例在这里
由于这是与此相关的问题的顶级搜索结果之一,我觉得值得一提的是如何使用Kendo()。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";
});
可以“本地”按值选择:
dropdownlist.select(1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.