javascript 将现有的 Kendo 网格绑定到新的 JSON 对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19645135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Binding existing Kendo grid to a new JSON object
提问by Maven
I have following kendoGrid
on my page that on load receives JSON
object from the specified URL.
kendoGrid
我的页面上有以下内容,加载时JSON
从指定的 URL接收对象。
But later i want to bind it to some other JSON
data received from other source. Is there a way a can bind-refresh existing data containing grid with a new JSON
object?
但后来我想将它绑定JSON
到从其他来源收到的其他一些数据。有没有办法可以使用新JSON
对象绑定刷新包含网格的现有数据?
$('#grid').kendoGrid({
sortable: true,
groupable: true,
scrollable: true,
pageable: {
pageSizes: 9
},
dataSource: {
transport: {
read: {
url: "../Get/JsonData",
dataType: "Json"
}
}
},
columns: [
{ field: "name", title: "Name", width: 100 },
... ...
]
});
回答by CodingWithSpike
You could either replace all the data in the DataSource with:
您可以将 DataSource 中的所有数据替换为:
var newData = [ "some", "data", "array" ];
var gridWidget = $('#grid').data("kendoGrid");
gridWidget.dataSource.data(newData);
Or you can give the grid a whole new DataSource (I recommend this approach):
或者你可以给网格一个全新的数据源(我推荐这种方法):
var newData = new kendo.data.DataSource({
data: [ "some", "data", "array" ]
});
var gridWidget = $('#grid').data("kendoGrid");
gridWidget.setDataSource(newData);
and of course newData
in my example would just be whatever data is returned from your function.
当然,newData
在我的示例中,只是从您的函数返回的任何数据。
回答by OnaBai
Is the structure of the new JSON the same (same columns and same data model)? If so then yes, just play with transport.read
or transport.read.url
and instead of defining it as a string
define it as a function that returns either one or the other.
新 JSON 的结构是否相同(相同的列和相同的数据模型)?如果是,那么是的,只需使用transport.read
ortransport.read.url
和而不是将其string
定义为将其定义为返回一个或另一个的函数。
Remember that transport.read
might be an object or a function. Same happens for transport.read.url
请记住,它transport.read
可能是一个对象或一个函数。同样发生在transport.read.url