Javascript 如何从AJAX响应数据呈现剑道UI网格?
我有一段代码,它从一个静态url获取json对象,然后呈现网格。但我想使用json数据作为AJAX响应检索,然后使用此响应文本呈现网格因为对于实际部署,我不能使用静态URL。Javascript 如何从AJAX响应数据呈现剑道UI网格?,javascript,jquery,ajax,kendo-ui,kendo-grid,Javascript,Jquery,Ajax,Kendo Ui,Kendo Grid,我有一段代码,它从一个静态url获取json对象,然后呈现网格。但我想使用json数据作为AJAX响应检索,然后使用此响应文本呈现网格因为对于实际部署,我不能使用静态URL。 $("#grid").kendoGrid({ dataSource: { type: "json", transport: { read: {url: "http://url/returnsjsonobject.php"} //
$("#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: function(options) {
return "somefunctionalcall?id=" + options.id,
},
dataType: "json"
}
transport: {
read: function (options) {
$.ajax({
dataType: "json",
url: "somefunctionalcall",
success: function (d) {
options.success(d);
}
});
}
}
甚至定义为一个函数:
transport: {
read: {
url: function(options) {
return "somefunctionalcall?id=" + options.id,
},
dataType: "json"
}
transport: {
read: function (options) {
$.ajax({
dataType: "json",
url: "somefunctionalcall",
success: function (d) {
options.success(d);
}
});
}
}
记住,它不一定是常数,但可能是函数:
transport: {
read: {
url: function(options) {
return "somefunctionalcall?id=" + options.id,
},
dataType: "json"
}
transport: {
read: function (options) {
$.ajax({
dataType: "json",
url: "somefunctionalcall",
success: function (d) {
options.success(d);
}
});
}
}
甚至定义为一个函数:
transport: {
read: {
url: function(options) {
return "somefunctionalcall?id=" + options.id,
},
dataType: "json"
}
transport: {
read: function (options) {
$.ajax({
dataType: "json",
url: "somefunctionalcall",
success: function (d) {
options.success(d);
}
});
}
}