【发布时间】:2017-05-18 10:35:42
【问题描述】:
我正在使用 Spring Boot Angular js 开发应用程序。在这里,我正在处理 json 数组和 json 对象以使用 abn-tree 构造树。
树构造良好。由于此树将在单击每个节点时更新,这意味着子节点将在运行时添加,就像通过从数据库加载单击时一样。
树 JSON 就像:
[{"parent":"Title-1","expanded":true,"label":"Title-1","children":[
{"parent":"Title-1","expanded":true,"label":"Chapter-I", "children":[
{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-1"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-10"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-100"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-11"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-12"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-13"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-14"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-140"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-49"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-5"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-50"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-7"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-75"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-8"},{"parent":"Chapter-I","expanded":false,"children":[],"label":"Part-9"}]},
{"parent":"Title-1","expanded":true,"label":"Chapter-II","children":[
{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-200"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-201"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-202"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-203"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-204"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-205"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-209"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-210"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-211"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-285"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-286"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-287"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-288"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-289"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-290"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-300"},{"parent":"Chapter-II","expanded":false,"children":[],"label":"Part-301"}]}]
}]
上面返回UI并显示树,所以我在后端资源类中构造这个json以避免js文件中的代码。
随着每个部分将添加子部分/子组等,此 json 将增长更多...下一个子部分将添加它们的子部分。所以 part..subpart.. 的孩子将添加对象来加载他们的孩子。
这个 json 越长越长。循环也在增加。有没有什么简单的方法可以让给定字符串的 jsonarray 在不循环的情况下添加更多的子元素。
就像我想要 Part-200 的孩子一样,我只提供节点的名称并获取 Part-200 的 json 数组,而不需要循环和迭代?
【问题讨论】:
标签: java json spring-boot