jsGrid 未加载 Spring-启动 json
jsGrid not loading Spring-boot json
Restfull api returns json 很好。尝试使用 json 数据填充 html 页面上的 jsGrid。必须从根本上做错事,因为我发现的所有示例都失败了。我看到的是带有 'Not found' 的列名称仅写为行。
有什么想法吗?
这仍然给我 "Not Found":
controller: {
loadData: function(filter) {
return {
data: [{"Name":"Edmund","Age": "25"},
{"Name":"Edmund","Age": "25"}
],
itemsCount: 2
};
}
},
fields: [
{ name: "Name", type: "text", width: 150 },
{ name: "Age", type: "text", width: 50 }
]
});
jsGrid 需要以下格式的数据。
{"data":[...],"itemsCount":<data count>}
最初,我遇到了同样的问题。所以,我首先尝试从控制器发送一个硬编码的字符串,如下所示
String responseStr = "{\"data\":[{\"fld_1\": \"val1\",\"fld_2\": \"val2\"},{\"fld_1\": \"val3\",\"fld_2\": \"val4\"],\"itemsCount\":2}";
成功了。现在,我们使用一些数据对象如下
public class MyDataDO {
private List<Map<String, Object>> data;
private int itemsCount;
//setter/getter
}
此外,您能否确定 autoload
设置为正确的值?
编辑:
您可以按照下面的方式进行
...
controller: {
loadData: function(filter) {
return {
data: [{"field_1":"val1","field_2": "val2"},
{"field_1":"val3","field_2": "val4"}
],
itemsCount: 2
};
}
}
以下页面显示正常。所有js和css文件都来自jsgrid自带的发行版
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="demos.css" />
<link rel="stylesheet" type="text/css" href="../css/jsgrid.css" />
<link rel="stylesheet" type="text/css" href="../css/theme.css" />
<script src="../external/jquery/jquery-1.8.3.js"></script>
<script src="../src/jsgrid.core.js"></script>
<script src="../src/jsgrid.load-indicator.js"></script>
<script src="../src/jsgrid.load-strategies.js"></script>
<script src="../src/jsgrid.sort-strategies.js"></script>
<script src="../src/jsgrid.field.js"></script>
</head>
<body>
<div id="jsGrid"></div>
<script>
$(function() {
$("#jsGrid").jsGrid({
pageLoading : true,
autoload: true,
controller: {
loadData: function(filter) {
return {
data: [
{"Name":"Edmund","Age": "25"},
{"Name":"Edmund","Age": "25"}
],
itemsCount: 2
};
},
},
fields: [
{ name: "Name", type: "text", width: 100 },
{ name: "Age", type: "text", width:150}
]
});
});
</script>
</body>
</html>
Restfull api returns json 很好。尝试使用 json 数据填充 html 页面上的 jsGrid。必须从根本上做错事,因为我发现的所有示例都失败了。我看到的是带有 'Not found' 的列名称仅写为行。
有什么想法吗?
这仍然给我 "Not Found":
controller: {
loadData: function(filter) {
return {
data: [{"Name":"Edmund","Age": "25"},
{"Name":"Edmund","Age": "25"}
],
itemsCount: 2
};
}
},
fields: [
{ name: "Name", type: "text", width: 150 },
{ name: "Age", type: "text", width: 50 }
]
});
jsGrid 需要以下格式的数据。
{"data":[...],"itemsCount":<data count>}
最初,我遇到了同样的问题。所以,我首先尝试从控制器发送一个硬编码的字符串,如下所示
String responseStr = "{\"data\":[{\"fld_1\": \"val1\",\"fld_2\": \"val2\"},{\"fld_1\": \"val3\",\"fld_2\": \"val4\"],\"itemsCount\":2}";
成功了。现在,我们使用一些数据对象如下
public class MyDataDO {
private List<Map<String, Object>> data;
private int itemsCount;
//setter/getter
}
此外,您能否确定 autoload
设置为正确的值?
编辑:
您可以按照下面的方式进行
...
controller: {
loadData: function(filter) {
return {
data: [{"field_1":"val1","field_2": "val2"},
{"field_1":"val3","field_2": "val4"}
],
itemsCount: 2
};
}
}
以下页面显示正常。所有js和css文件都来自jsgrid自带的发行版
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="demos.css" />
<link rel="stylesheet" type="text/css" href="../css/jsgrid.css" />
<link rel="stylesheet" type="text/css" href="../css/theme.css" />
<script src="../external/jquery/jquery-1.8.3.js"></script>
<script src="../src/jsgrid.core.js"></script>
<script src="../src/jsgrid.load-indicator.js"></script>
<script src="../src/jsgrid.load-strategies.js"></script>
<script src="../src/jsgrid.sort-strategies.js"></script>
<script src="../src/jsgrid.field.js"></script>
</head>
<body>
<div id="jsGrid"></div>
<script>
$(function() {
$("#jsGrid").jsGrid({
pageLoading : true,
autoload: true,
controller: {
loadData: function(filter) {
return {
data: [
{"Name":"Edmund","Age": "25"},
{"Name":"Edmund","Age": "25"}
],
itemsCount: 2
};
},
},
fields: [
{ name: "Name", type: "text", width: 100 },
{ name: "Age", type: "text", width:150}
]
});
});
</script>
</body>
</html>