Kendo UI动态更改数据源字符串(XML)

我有一个绑定到XML DataSource的Kendo Grid。 如何根据下拉列表的选择更改DataSource。 例:

//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();