我有一个绑定(bind)到 XML 数据源的 Kendo 网格。如何根据下拉列表的选择更改数据源。示例:
//Create DataSource
var gridDataSource = new kendo.data.DataSource({
transport: {
read: [DropDownListValue] + ".xml",
dataType: "xml"
}
});
gridDataSource.read();
function createGrid(){
var grid = $("#grid").kendoGrid({
dataSource: gridDataSource
}...
};
其中 [DropDownListValue] 是我表单上的下拉列表。在此示例中,如果 [DropDownListValue] = 1,则数据源将为“1.xml”。如果 [DropDownListValue] = 2,则数据源将为“2.xml”。
最佳答案
我能够通过将以下内容添加到我的下拉列表的 On Change 事件中来实现这一点:
//Assign drop down value to variable
var dropDownListValue = $("#dropDown1").val();
//Concatenate drop down variable to file name
var dynamicUrl = dropDownListValue +".xml";
//Assign grid to variable
var grid = $("#grid").data("kendoGrid");
//Set url property of the grid data source
grid.dataSource.transport.options.read.url =dynamicUrl;
//Read data source to update
grid.dataSource.read();
关于jquery - Kendo UI 动态更改数据源字符串 (XML),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12254334/