Kendo UI 动态更改数据源字符串 (XML) [英] Kendo UI Dynamically Change Datasource String (XML)
本文介绍了Kendo UI 动态更改数据源字符串 (XML)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个绑定到 XML 数据源的 Kendo Grid.如何根据下拉列表的选择更改数据源.示例:
I have a Kendo Grid that binds to an XML DataSource. How can I have the DataSource change, based off the selection of a drop down list. Example:
//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".
Where [DropDownListValue] is a drop down list on my form. In this example if [DropDownListValue] = 1, the datasource would be "1.xml". If [DropDownListValue] = 2, then datasource would be "2.xml".
推荐答案
我能够通过将以下内容添加到我的下拉列表的 On Change 事件来实现这一点:
I was able to achieve this by adding the following to the On Change event of my Drop Down list:
//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();
这篇关于Kendo UI 动态更改数据源字符串 (XML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文