此处显示非常简单的案例: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
中具有不同的用途。大批。目前没有允许指定用于级联的字段的功能。
您有两个选择:
categoriesList
的“id”字段到“categorie_id”并设置 dataValueField
因此。 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/