SmartGWT TreeGrid 数据源由嵌套数组 JSON 填充
我尝试按照示例执行相同操作,但使用 JSON 而不是 XML
当我使用 XML 执行此操作时,它工作得很好,但当我使用 JSON 时,它仅加载第一个子级。
这是 XML:
<response>
<errors />
<data>
<project>
<id>3</id>
<name>Checho Project</name>
<sprints>
<project>
<id>4</id>
<name>Backlog</name>
</project>
</sprints>
</project>
</data>
</response>
这是 JSON:
{"response":
{"errors":"","data":
{"project":[{"id":1,"name":"Bee Project","sprints":
{"project":[{"id":3,"name":"sprint3"},{"id":4,"name":"sprint2"},{"id":2,"name":"sprint1"}]}},
{"id":5,"name":"Checho Project","sprints":
{"project":{"id":6,"name":"Backlog"}}}]
}
}
}
private ProjectDS(String id) {
setID(id);
setRecordXPath("/response/data/*");
// setRecordXPath("/Employees/*");
// DataSourceTextField nameField = new DataSourceTextField("Name", "Name", 128);
//
// DataSourceIntegerField employeeIdField = new DataSourceIntegerField("EmployeeId", "Employee ID");
// employeeIdField.setPrimaryKey(true);
// employeeIdField.setRequired(true);
DataSourceTextField idField = new DataSourceTextField("id", "Id", 128, true);
idField.setHidden(true);
idField.setPrimaryKey(true);
DataSourceTextField itemNameField = new DataSourceTextField("name", "Item", 128, true);
DataSourceField reportsToField = new DataSourceField();
reportsToField.setName("sprints");
reportsToField.setChildrenProperty(true);
setFields(idField, itemNameField, reportsToField);
setDataFormat(DSDataFormat.JSON);
setDataURL("bee_gui/sc/ds.xml");
setClientOnly(true);
}
有人处理过这个吗?
谢谢!
I have tried to do the same as the sample says but using JSON instead of XML
When i do it using XML, it works perfectly, but it only loads first childs when i use JSON.
Here is the XML:
<response>
<errors />
<data>
<project>
<id>3</id>
<name>Checho Project</name>
<sprints>
<project>
<id>4</id>
<name>Backlog</name>
</project>
</sprints>
</project>
</data>
</response>
And here is the JSON:
{"response":
{"errors":"","data":
{"project":[{"id":1,"name":"Bee Project","sprints":
{"project":[{"id":3,"name":"sprint3"},{"id":4,"name":"sprint2"},{"id":2,"name":"sprint1"}]}},
{"id":5,"name":"Checho Project","sprints":
{"project":{"id":6,"name":"Backlog"}}}]
}
}
}
private ProjectDS(String id) {
setID(id);
setRecordXPath("/response/data/*");
// setRecordXPath("/Employees/*");
// DataSourceTextField nameField = new DataSourceTextField("Name", "Name", 128);
//
// DataSourceIntegerField employeeIdField = new DataSourceIntegerField("EmployeeId", "Employee ID");
// employeeIdField.setPrimaryKey(true);
// employeeIdField.setRequired(true);
DataSourceTextField idField = new DataSourceTextField("id", "Id", 128, true);
idField.setHidden(true);
idField.setPrimaryKey(true);
DataSourceTextField itemNameField = new DataSourceTextField("name", "Item", 128, true);
DataSourceField reportsToField = new DataSourceField();
reportsToField.setName("sprints");
reportsToField.setChildrenProperty(true);
setFields(idField, itemNameField, reportsToField);
setDataFormat(DSDataFormat.JSON);
setDataURL("bee_gui/sc/ds.xml");
setClientOnly(true);
}
Did anyone deal with this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以这种方式使用 JSON 对象,你就会得到解决方案
Use the JSON object in this fashion then you will get the solution
我使用“Javascript Overly Types”进行 JSON 解析
,如果您想了解更多信息,请看这里:http://googlewebtoolkit.blogspot.com/2008/08/getting-to-really-know-gwt-part-2.html
它们非常简单,而且工作得非常好!
PS:对不起,我无法帮助你举出你的例子......
I use "Javascript Overly Types" for my JSON parsing
Take a look here, if you want to know more: http://googlewebtoolkit.blogspot.com/2008/08/getting-to-really-know-gwt-part-2.html
They are pretty easy an work really well!
PS: Sry that I can't help you with your example...