2

我尝试按照示例中的说明做同样的事情,但使用 JSON 而不是 XML

智能 GWT 树

当我使用 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);

}

有人处理过这个吗?

谢谢!

4

2 回答 2

0

我使用“Javascript Overly Types”进行 JSON 解析

如果您想了解更多信息,请看这里:http: //googlewebtoolkit.blogspot.com/2008/08/getting-to-really-know-gwt-part-2.html

他们很容易工作非常好!

PS:对不起,我不能帮助你的例子......

于 2011-08-09T16:06:27.993 回答
0

以这种方式使用 JSON 对象,您将获得解决方案

{"List":
    {"employee":
        [{"EmployeeId":4,"ReportsTo":1,"Name":"Seg 1", "Job":"Chief Operating Officer","Salary":260000},{"EmployeeId":192,"ReportsTo":4,"Name":"Leg 1","Job":"Mgr Cap Rptg Dist","Salary":460000},{"EmployeeId":5,"ReportsTo":1,"Name":"Seg 2", "Job":"Chief Operating Officer","Salary":260000},{"EmployeeId":193,"ReportsTo":5,"Name":"Leg 2","Job":"Mgr Cap Rptg Dist","Salary":460000}]
    }
}
于 2011-10-05T06:48:37.873 回答