【问题标题】:Kendo dropdown rebind using jquery使用 jquery 重新绑定剑道下拉菜单
【发布时间】:2013-09-06 10:58:32
【问题描述】:

我正在尝试使用 dropDown.setDataSource(result) 事件将 SelectList 项目列表绑定到 jquery 中的 Kendo 下拉列表。但问题是,下拉列表中显示的数据显示为[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);
                    }
                });
        }
    });

【问题讨论】:

标签: jquery asp.net-mvc asp.net-mvc-3 kendo-ui kendo-combobox


【解决方案1】:

试试这个, 这只是一个例子,

       @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);
        }

效果很好。

【讨论】:

  • 实际上我正在使用@html.kendo().dropDOwnList().Name("exportTypeDropDown") 来创建下拉列表
  • @Rudresh:我只是更新我的代码。试试这个,如果有任何问题,请告诉我。
【解决方案2】:

这是因为 kendo 不知道您想将SelectListItems 对象的哪个属性与下拉列表ValueText 绑定。

$('#exportTypeDropDown').kendoDropDownList({
    dataTextField: "Text",
    dataValueField: "Value",
    autoBind: false
});

请确保在设置dataSource 之前执行此操作。

【讨论】:

  • 您的浏览器是否从服务器获取正确的数据?从浏览器的网络选项卡检查。
  • 是的,它正在将 SelectedListItem 列表作为 [object object],[object object] 并且在那个对象中我正在获取数据
猜你喜欢
  • 1970-01-01
  • 2017-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-17
  • 2023-03-09
  • 1970-01-01
相关资源
最近更新 更多