SmartGWT TreeGrid 数据源由嵌套数组 JSON 填充

发布于 2024-11-19 07:51:56 字数 2105 浏览 5 评论 0原文

我尝试按照示例执行相同操作,但使用 JSON 而不是 XML

Smart GWT Tree

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

Smart GWT Tree

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

他不在意 2024-11-26 07:51:56

以这种方式使用 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}]
    }
}

Use the JSON object in this fashion then you will get the solution

{"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}]
    }
}
拍不死你 2024-11-26 07:51:56

我使用“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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文