Kendo UI 团队提供了一个示例代码来执行级联多个 Kendo UI MultiSelect 小部件。下面的例子演示了如何做......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.714/styles/kendo.common.min.css" />
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.714/styles/kendo.rtl.min.css" />
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.714/styles/kendo.silver.min.css" />
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.714/styles/kendo.mobile.all.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.2.714/js/kendo.all.min.js"></script>
</head>
<body>
supplier: <select id="suppliers"></select>
product: <select id="products"></select>
<script>
$(function () {
var productsDataSource = new kendo.data.DataSource({
type: "odata",
serverFiltering: true,
transport: {
read: {
url: "http://demos.kendoui.com/service/Northwind.svc/Products",
},
parameterMap: function (data) {
return kendo.data.transports.odata.parameterMap.call(this, data);
}
}
});
$("#products").kendoMultiSelect({
autoBind: false,
dataTextField: "ProductName",
dataValueField: "ProductID",
dataSource: productsDataSource
});
$("#suppliers").kendoMultiSelect({
autoBind: false,
dataTextField: "CompanyName",
dataValueField: "SupplierID",
dataSource: {
type: "odata",
serverFiltering: true,
transport: {
read: {
url: "http://demos.kendoui.com/service/Northwind.svc/Suppliers"
}
}
},
change: function () {
var filters = buildFilters(this.dataItems());
productsDataSource.filter(filters);
}
});
function buildFilters(dataItems) {
var filters = [],
length = dataItems.length,
idx = 0, dataItem;
for (; idx < length; idx++) {
dataItem = dataItems[idx];
filters.push({
field: "SupplierID",
operator: "eq",
value: parseInt(dataItem.SupplierID)
});
}
return {
logic: "or",
filters: filters
};
}
});
</script>
</body>
</html>