基于数据库数据的树结构+更快的树操作
我想在我的网站上有一个基于数据库数据的“n”级树。我已经决定了我的java数据结构。但我担心当尝试从我的 java 数据结构(带有父级、子级列表的通用树元素)呈现我的详细信息时,我可能会失去一些客户端性能。
现在正在验证 2 个选项:
- 尝试使用纯 JSP 标签/Javascript 或 Ajax 呈现我的 java 数据结构
- 从我的数据结构中准备 JSON 并在客户端使用 JSON。计划使用GSON进行序列化和反序列化,不知道这是否是一个开销。因为我经常需要根据过滤器/搜索等刷新我的树,
我需要支持的树操作是:
- 遍历 - 一次可以扩展多个分支,我的树(更多的是一张图)可以在以下位置重复相同的分支 我需要显示计数的不同级别
- ,并且计数可以根据应用的某些过滤器而改变(例如价格<20)
处理此问题的最佳方法是什么。
I would like to have a 'n' level tree on my website, that is based on the data from database. I have made my mind on my java data structure. But i fear that i might loose some client side performance when trying to render my details from my java data structure (generic tree element with parent,list of children).
Now am validating 2 options:
- Try and render my java data structure using plain JSP tags / Javascript or Ajax
- Prepare a JSON from my data structure and work with JSON on my client side. PLanning to use GSON for serialze and De-serialize,don't know if this is an overhead. Cause i constantly have to refresh my tree based on filters/search etc
Tree operations i need to support are:
- Traversal - More than one branch could be expanded at a time, my tree(more of a graph) can have the same branch repeating at different levels
- I need to display count and the count can change based on some filters applied (for e.g. price < 20)
What is the best way to handle this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的树有多大?数千个或数百万个元素?如果节点数< 1000,性能不是问题。
大多数情况下,该数字将小于 10,因为使用 AJAX,您可以单独推送树的每个分支,因此只有最大的分支才算数。假设最大的分支是 1000,但平均分支有 10 个节点。在这种情况下,您可以忽略性能。
您应该做什么:选择合适的 JavaScript 框架来为您构建树。不要自己尝试这个。有些微妙的浏览器错误和差异会让你发疯。相反,请尝试使用 jQuery Treeview 插件之类的东西。
How big is your tree? Thousands or millions of elements? If the number of nodes is < 1000, performance is not an issue.
And most of the time, the number will be <10 since with AJAX, you can push each branch of the tree individually, so only the largest branch counts - somewhat. Say the largest branch is 1000 but the average branch has 10 nodes. In this case, you can ignore performance.
What you should do: Select an appropriate JavaScript framework to build the tree for you. Don't try this yourself. There are subtle browser bugs and differences that will drive you insane. Instead, try something like the jQuery Treeview plugin.