我有这段代码,它从静态网址获取json对象,然后渲染网格。但我想使用作为 AJAX 响应检索的 json 数据,然后使用此响应文本渲染网格。 因为在实际部署中我无法使用静态 URL。
$("#grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {url: "http://url/returnsjsonobject.php"}
//THIS GETS DATA FROM STATIC URL BUT I WANT TO READ DATA AS AJAX RESPONSE
//like read: somefunctioncall
//or like read: somevariable
},
schema: {
model: {
fields: {
id: {type: "string", editable: false},
name: {type: "string"}
}
}
},
pageSize: 20
},
height: 430
columns: [
{field: "id", title: "ID", width: "20px", hidden: "true"},
"name",
});
提前感谢您的帮助以及您是否有任何替代方法;我很乐意尝试。
最佳答案
请记住transport.read.url
不一定是常量,但可以是函数:
transport: {
read: {
url: function(options) {
return "somefunctionalcall?id=" + options.id,
},
dataType: "json"
}
甚至定义 transport.read
作为一个函数:
transport: {
read: function (options) {
$.ajax({
dataType: "json",
url: "somefunctionalcall",
success: function (d) {
options.success(d);
}
});
}
}
关于javascript - 如何从 AJAX 响应数据渲染 Kendo UI 网格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20742061/