0
var test = $("#TestDropdown").kendoDropDownList({
                dataTextField: "test",
                dataValueField: 'testing',
                filter: "contains",
                autoBind: false,
                minLength: 2,
                dataSource: {
                    transport: {
                        read: {
                            url: 
                            complete: function (jqXHR, textStatus) {
                            }
                        },
                    },
                    schema: {
                        test: {editable: true, type: "string"},
                        testing: {editable: true, type: "number"},
                    }
                }
            });

假设我的下拉列表有 3 个值,红色、黄色、绿色。如果当前选择了绿色,我如何创建不能更改为黄色的验证,或者这可能吗?

4

1 回答 1

0

您可以按照文档中的方法

select: function(e) {
  if (e.dataItem.isDeleted) {
    e.preventDefault(); // it will stop from selection
  }
},

    
    
    
      $("#dropdownlist").kendoDropDownList({
        dataSource: [
          { id: 1, name: "Apples", isDeleted: false},
          { id: 3, name: "Mangoes", isDeleted: true},
          { id: 2, name: "Oranges" , isDeleted: false}
        ],
        dataTextField: "name",
        dataValueField: "id",
        select: function(e){
          if(e.dataItem.isDeleted){
            e.preventDefault();
          }
        },
        template: kendo.template($("#template").html())
      });

      $(".k-button").click(function(){
        var dropdown = $("#dropdownlist").data("kendoDropDownList");
        var oranges = dropdown.dataSource.get(2);
        oranges.set("isDeleted", true);
      })
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.1018/styles/kendo.common-material.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.1018/styles/kendo.material.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.1018/styles/kendo.material.mobile.min.css" />

    <script src="https://kendo.cdn.telerik.com/2017.3.1018/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2017.3.1018/js/kendo.all.min.js"></script>
<input id="dropdownlist" /> <button class="k-button"> Mark Oranges as deleted</button>
<script id="template" type="text/x-kendo-template">
    <span class="#: isDeleted ? 'k-state-disabled': ''#">
       #: name #
    </span>
    </script>

于 2017-10-26T13:00:35.247 回答