gpt4 book ai didi

json - Kendo UI Grid JSON DataSource 未加载数据

转载 作者:行者123 更新时间:2023-12-03 16:56:38 25 4
gpt4 key购买 nike

出于某种原因,我似乎无法在 Kendo UI Grid 中获得以下内容:

grid-image

HTML:

<div id="grid"></div>
<script>
var remoteDataSource = new kendo.data.DataSource(
{
transport:
{
read: {
type: "POST",
dataType: "json",
url: "/home/getopportunities/"
}
},
pageSize: 4
})
$("#grid").kendoGrid(
{
dataSource: remoteDataSource,
columns: [
{
title: "Title",
headerAttributes: {
style: "text-align:center"
},
attributes: {
"class": "table-cell"
},
width: 600,
filterable: true
},
{
title: "Activity Type",
headerAttributes: {
},
attributes: {
"class": "table-cell",
style: "text-align:center"
},
width: 100,
filterable: true
},
{
title: "Specialty",
filterable: true,
headerAttributes: {
style: "text-align:center"
},
attributes: {
"class": "table-cell",
style: "text-align:center"
}
},
{
title: "Total Credits",
format: "{0}",
headerAttributes: {
style: "text-align:center"
},
attributes: {
"class": "table-cell",
style: "text-align:center"
}
}
],
height: 430,
scrollable: true,
sortable: true,
pageable: true,
filterable: {
extra: false,
operators: {
string: {
contains: "Contains",
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to"
},
number: {
eq: "Is equal to",
neq: "Is not equal to",
gte: "Greater Than",
lte: "Less Than"
}
}
}
});
</script>

这是返回给它的 JSON:
[
{"ActivityID":367,"Title":"Non Webinar Test For Calendar","ActivityType":"Other","TotalCredits":2,"Specialty":"[AB] [AE]"},
{"ActivityID":370,"Title":"Stage - Test SI Changes Part II","ActivityType":"Other","TotalCredits":2,"Specialty":"[NE]"},
{"ActivityID":374,"Title":"Webinar Test Event For Calendar","ActivityType":"Webinar","TotalCredits":2,"Specialty":"[FE] [NE] "},
{"ActivityID":401,"Title":"Module #1 Webinar: Learn Stuff","ActivityType":"Webinar","TotalCredits":2,"Specialty":"[AB] ",},
{"ActivityID":403,"Title":"Module #3 Webinar: Learn Even More Stuff","ActivityType":"Webinar","TotalCredits":2,"Specialty":"[AB] [AE]",}
]

我觉得我真的很接近但我错过了最后一块。任何帮助将不胜感激,因为我在最后期限。

最佳答案

常见的问题是缺少架构属性!
将它添加到网格的 - 数据源,并在您制作 json 时检查它是否已设置。

(当普通数组被序列化/to_json 时,数据数组需要一个指示shema 的属性)

这里有一个例子来说明:

js:示例网格初始化/数据源:

$("#grid").kendoGrid({ dataSource: { transport: { read: "/getdata/fromthisurl" }, schema: { data: "data" } } });

当你制作/输出你的json时,看看编码结果中是否有shema信息:

php:
 $somedata= get_my_data();

header("Content-type: application/json");
echo "{\"data\":" .json_encode($somedata). "}";

或者:
     $viewdata['data'] = get_my_data();

header("Content-type: application/json");
echo (json_encode($viewdata));

所以发送到网格的 json 看起来像:
{data:
[
{item}
{item}
]
}

而不仅仅是:
[
{item}
{item}
]

关于json - Kendo UI Grid JSON DataSource 未加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18222416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com