如何通过javascript或Jquery为kendo下拉列表设置过滤器属性

时间:2017-09-04 08:58:25

标签: javascript jquery kendo-ui kendo-dropdown

我在cshtml中有一个kendo下拉列表。我想在Jquery或javasctipt中设置filter属性。你能告诉我如何实现这个目标吗? 感谢您对此的帮助。

 @(Html.Kendo().DropDownList()
          .Name("movies")
          .DataTextField("Text")
          .DataValueField("Value")
          .HtmlAttributes(new { style = "width: 100%" })
          .BindTo(new List<SelectListItem>()
          {
              new SelectListItem() {
                Text = "The Shawshank Redemption", Value ="1"
              },
              new SelectListItem() {
                Text = "The Godfather", Value ="2"
              },
              new SelectListItem() {
                Text = "The Godfather: Part II", Value ="3"
              },
              new SelectListItem() {
                Text = "Il buono, il brutto, il cattivo.", Value ="4"
              },
              new SelectListItem() {
                Text = "Pulp Fiction", Value ="5"
              },
              new SelectListItem() {
                Text = "12 Angry Men", Value ="6"
              },
              new SelectListItem() {
                Text = "Schindler's List", Value ="7"
              },
              new SelectListItem() {
                Text = "One Flew Over the Cuckoo's Nest", Value ="8"
              },
              new SelectListItem() {
                Text = "Inception", Value ="9"
              },
              new SelectListItem() {
                Text = "The Dark Knight", Value ="10"
              }
          })
    )

1 个答案:

答案 0 :(得分:1)

更新:如果在创建时未设置过滤器,则使用过滤器销毁并重新初始化

在JavaScript / jQuery中获取下拉列表并调用destroy():

var dropdownlist = $("#movies").data("kendoDropDownList");
dropdownlist.destroy();

然后使用过滤器重新创建:

$("#products").kendoDropDownList({
  dataTextField: "ProductName",
  dataValueField: "ProductID",
  dataSource: {
    transport: {
         read: {
            dataType: "jsonp",
            url: "https://demos.telerik.com/kendo-ui/service/Products",
         }
    }
  },
  filter: filt
});

<强> DEMO