使用jquery的Kendo下拉列表重新绑定 [英] Kendo dropdown rebind using jquery
本文介绍了使用jquery的Kendo下拉列表重新绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是尝试使用 dropDown.setDataSource(result)
事件将 SelectList
项列表绑定到jquery中的Kendo下拉列表。但问题是,下拉列表中显示的数据显示为 [object object]
。
I am trying to bind a list of SelectList
Items to a Kendo dropdown in jquery using dropDown.setDataSource(result)
event. But the issue is, the data displayed in the drop-down is showing as [object object]
.
$(document).ajaxStop(function () {
var exportTypeDropDown = $("#exportTypeDropDown").data("kendoDropDownList");
if (dropDownLoaded == false && exportTypeDropDown!=null) {
dropDownLoaded = true;
var url = "@Url.Action("GetExportTypes", UiControls.ControllerName)";
$.ajax({
url: url,
type: "POST",
traditional: true,
success: function (result) {
exportTypeDropDown.setDataSource(result);
}
});
}
});
推荐答案
试试这个,
这只是一个例子,
Try this, This is just example,
@Html.DropDownList("CustomerId", (SelectList)ViewBag.CustomerNameID, "--Select--")
@(Html.Kendo().DropDownList()
.Name("ddlSearchPNResults")
.DataTextField("Text")
.DataValueField("Value")
.AutoBind(false)
.CascadeFrom("CustomerId"))
脚本
$(document).ready(function () {
$("#CustomerId").change(function () {
var ddl = $('#ddlSearchPNResults').data("kendoDropDownList");
var Id = $("#CustomerId").val();
$.ajax({
url: '@Url.Action("GetCustomerNameWithId", "Test")',
type: "Post",
data: { CustomerNameId: Id },
success: function (listItems) {
ddl.setDataSource(listItems);
}
});
});
});
控制器
public JsonResult GetCustomerNameWithId(string CustomerNameId)
{
int _CustomerNameId = 0;
int.TryParse(CustomerNameId, out _CustomerNameId);
var listItems = GetCustomerNameId(_CustomerNameId).Select(s => new SelectListItem { Value = s.CID.ToString(), Text = s.CustomerName }).ToList<SelectListItem>();
return Json(listItems, JsonRequestBehavior.AllowGet);
}
完美无缺。
这篇关于使用jquery的Kendo下拉列表重新绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文