我正在尝试从SPRING Web MVC加载网格中的远程数据。 这是我的控制器方法:
@SuppressWarnings("unchecked")
@RequestMapping(value = "/remote-data-binding/read", method = RequestMethod.POST)
public @ResponseBody String read() {
JSONObject obj = new JSONObject();
JSONArray arr = new JSONArray();
obj.put("id", "1");
obj.put("name", "thomas");
obj.put("decription", "erster Eintrag");
arr.add(obj);
obj = new JSONObject();
obj.put("id", "2");
obj.put("name", "Dieter");
obj.put("decription", "zweiter Eintrag");
arr.add(obj);
return arr.toJSONString();
}
我的JSP看起来像这样:
<h2>Table/Grid Test</h2>
<kendo:grid name="TestGrid" pageable="true" sortable="true" selectable="multiple" resizable="true" groupable="true" reorderable="true">
<kendo:grid-columns>
<kendo:grid-column title="Nummer" field="id" />
<kendo:grid-column title="Name" field="name" />
<kendo:grid-column title="Beschreibung" field="description" />
</kendo:grid-columns>
<kendo:dataSource pageSize="20" serverPaging="true" serverSorting="true" serverFiltering="true" serverGrouping="true">
<kendo:dataSource-transport>
<kendo:dataSource-transport-read url="remote-data-binding/read.html " type="POST" contentType="application/json"/>
<kendo:dataSource-transport-parameterMap>
function(options){return JSON.stringify(options);}
</kendo:dataSource-transport-parameterMap>
</kendo:dataSource-transport>
</kendo:dataSource>
<kendo:grid-pageable input="true" numeric="false" />
</kendo:grid>
我在浏览器中检查了响应:
[{"decription":"erster Eintrag","name":"thomas","id":"1"},{"decription":"zweiter Eintrag","name":"Dieter","id":"2"}]
网格未填充!为什么?
答案 0 :(得分:0)
有必要向数据源添加架构,如下例所示:
<kendo:dataSource-schema groups="data">
<kendo:dataSource-schema-model id="id">
<kendo:dataSource-schema-model-fields>
<kendo:dataSource-schema-model-field name="name"
type="string" />
<kendo:dataSource-schema-model-field name="location"
type="string" />
<kendo:dataSource-schema-model-field name="description"
type="string" />
<kendo:dataSource-schema-model-field name="imagePath"
type="string" />
<kendo:dataSource-schema-model-field name="detailUrl"
type="string" />
<kendo:dataSource-schema-model-field name="providerStatus"
type="string" />
</kendo:dataSource-schema-model-fields>
</kendo:dataSource-schema-model>
</kendo:dataSource-schema>
根据响应的json结构,group-property也必须正确设置!