kendo-ui - 使我的级联 DropDownList 工作缺少什么

标签 kendo-ui kendo-combobox

此处显示非常简单的案例:http://jsbin.com/ahoYoPi/3/edit

我需要指定 child 的内部字段来过滤(eq)对父的值字段是“category_id”......当然,Kendo的文档没有说明如何做到这一点......或者它是什么 super 显然它不值得解释?

    var categoriesList = new Array (
    {"id":"1","categoryName":"Fruits"},
    {"id":"2","categoryName":"Vegetables"} );

var productsList = new Array(
    {"id":"1","categorie_id":"1","productName":"Apples"},
    {"id":"2","categorie_id":"1","productName":"Oranges"},
    {"id":"3","categorie_id":"2","productName":"Carottes"},
    {"id":"4","categorie_id":"2","productName":"Patatoes"});

$("#categories").kendoDropDownList({
    dataTextField: "categoryName",
    dataValueField: "id",
    dataSource: categoriesList,
    optionLabel: "----------------" ,
    change: function() {
        $("#products").data("kendoDropDownList").value(0);
    }
});
$("#products").kendoDropDownList({
    cascadeFrom: "categories",
    dataTextField: "productName",
    dataValueField: "id",
    dataSource: productsList,
    optionLabel: "----------------" ,
});

最佳答案

有关级联的文档可在此处获得:http://docs.kendoui.com/getting-started/web/combobox/cascading

以下是过滤的工作原理:

If the parent has a value, then the child will be enabled and will filter its data depending on it. Here how the filter options will look like: field: "parentID", //the dataValueField of the parent operator: "eq", value: "" //parent's value



这意味着子下拉列表(组合框)将使用通过 dataValueField 配置的字段。父级进行过滤(级联)。在您的情况下,这不起作用,因为 dataValueField父项的设置为“id”。但是,该字段在 productsList 中具有不同的用途。大批。

目前没有允许指定用于级联的字段的功能。

您有两个选择:
  • 做@OnaBai 建议的事情。重命名 categoriesList 的“id”字段到“categorie_id”并设置 dataValueField因此。
  • 手动实现级联。首先删除 cascadeFrom 选项,然后在父级的更改事件中执行此操作:
    change: function() {
        var products = $("#products").data("kendoDropDownList");
    
        products.dataSource.filter( {
          field: "categorie_id",
          value: this.value(),
          operator: "eq"
        });
    
        products.value(0);
    }
    

    这是一个现场演示:http://jsbin.com/ogEj/1/edit
  • 关于kendo-ui - 使我的级联 DropDownList 工作缺少什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18347918/

    相关文章:

    kendo-ui - Kendo-Combobox的SelectionChange和ValueChange事件的区别

    html - Kendo 复选框切换 true 和 false 状态不能正常工作

    javascript - 在 ng-template 中使用 kendo-grid-column 的格式属性?

    javascript - Kendo Combobox - 设置全部来自数据库的多个组合框值

    javascript - 使 Kendo UI DropDownList 将 Select Control 的 Title 属性显示为 kendoTooltip

    javascript - 如何在剑道组合框完成过滤器后触发事件

    javascript - 从现有数据源创建新的 Kendo UI 数据源

    asp.net-mvc - Kendo UI 网格 ASP.NET MVC 包装器参数映射

    php - 剑道自动完成 : datasource update dynamically

    javascript - Kendo 网格内的单选按钮