Kendo ui 剑道网格未显示返回正确json的数据
在成功调用web方法并在ajax请求中看到返回的数据后,我的剑道网格没有显示数据Kendo ui 剑道网格未显示返回正确json的数据,kendo-ui,kendo-grid,Kendo Ui,Kendo Grid,在成功调用web方法并在ajax请求中看到返回的数据后,我的剑道网格没有显示数据 $(document).ready(function () { var filterSource = new kendo.data.DataSource({ transport: { read: function (options) { $.ajax({
$(document).ready(function () {
var filterSource = new kendo.data.DataSource({
transport: {
read: function (options) {
$.ajax({
type: "GET",
url: "DoJo.aspx/GetProjects",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// msg.d has the json data
}
});
}
},
schema: {
model: {
fields: {
ProjNum: { type: "string" },
Stat: { type: "string" }
}
},
data: "d"
},
change: function (e) {
// e.items is empty
}
});
$("#grid").kendoGrid({
dataSource: filterSource,
columns: [
{
field: "ProjNum", title: "Project Number", width: "130px", filterable: {
multi: true,
dataSource: filterSource
}
},
{
field: "Stat", title: "Status", filterable: {
multi: true,
dataSource: filterSource
}
}
]
});
})
下面的JSON是数组格式
[{"ProjNum":"12345","Stat":null,"ProjTitle":"Test Title","ClientName":"Test Client","ClientContactName":"Test Name","ClientFacilityLocation":"Test Location","SourceOfContact":"Test Contact","ProjManager":"Test Manager","Department":"Test Department"}]
为什么更改回调返回空的e.items?若我删除数据:“d”,它将返回带有json数据的e.Items 当您将
dataSource.transport.read
设置为函数并自己调用ajax调用时,需要将结果(或错误)传递回数据源,如下所示:
var filterSource = new kendo.data.DataSource({
transport: {
read: function (options) {
$.ajax({
type: "GET",
url: "DoJo.aspx/GetProjects",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// msg.d has the json data
// notify the data source that the request succeeded
options.success(msg);
},
error: function(msg) {
// notify the data source that the request failed
options.error(msg);
}
});
}
},
schema: {
model: {
fields: {
ProjNum: { type: "string" },
Stat: { type: "string" }
}
},
data: "d"
},
change: function (e) {
// e.items is empty
}
});
有关更多信息,请参阅。我已经添加了,但仍然不起作用。它显示分页信息,但网格仍然为空。您的响应数据的JSON片段是否完整?换句话说,它是响应根的数组吗?如果是这样的话,您不应该需要
数据:“d”
;这告诉数据源希望数据位于根对象的“d”
属性内,例如{d:[{obj1}、{obj2}、{obj3}}}我认为msg.d
属性在成功回调期间保存数据可能有点麻烦。我必须确保它是“实时”的,但是从数据源配置中删除数据:“d”
将解决JSON在msg.d中的问题(正如您已经演示的)。删除数据:“d”不起作用。为了让我们给您一个有根据的答案,您必须准确地告诉我们您的ajax调用返回的响应是什么。没有这些,我们只能猜测