我有以下下拉列表如果ViewBag.ServerId中的值设置为2,我想将dropdownlist设置为某个值
<script type="text/javascript">
$(document).ready(function () {
var data = [
{ text: "Selection 1", value: "1" },
{ text: "Selection 2", value: "2" }
];
$("#Cust").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: data,
index: 0,
optionLabel: {
text: "Please Select",
value: ""
}
});
var dropdownlist = $("#Cust").data("kendoDropDownList");
});
</script>
<div>
@if (ViewBag.serverId == 3)
{
so i would like to do something like this however i could reference dropdownlist.
dropdownlist.select(dropdownlist.ul.children().eq(2));
}
else
{
}
</div>
答案 0 :(得分:0)
I think you can do like this:
@if (ViewBag.serverId == 3)
{
<script type="text/javascript">
$(function() {
$("#Cust").data("kendoDropDownList").select(dropdownlist.ul.children().eq(2));
});
</script>
}
else
{
}
You know, if there are mutiple jQuery dom ready event in one page. They will be executed by order.
If the Kendo dropdown list component initialized in the prev context, I think you get the component instance from the element.
答案 1 :(得分:0)
您可以调整您的选择:
<script>
$(document).ready(function () {
$("#Cust").kendoDropDownList({
...
index: (parseInt(@ViewBag.ServerId) === 3) ? 2 : 0,
...
});
});
</script>