问题描述
我正在评估 Backbone javascript 框架,以便在将显示分层结构的项目中使用树视图小部件中的模型(想想 Windows 文件浏览器).
I'm evaluating the Backbone javascript framework for use in a project that will display a hierarchical model in a tree view widget (think the Windows file browser).
我喜欢 Backbone 对世界的看法.但是,在我获得 Backbone 实际上从服务器接收分层模型并更新树小部件的概念证明之前,涉及很多编码.我已经看到 用 Backbone 表示深层数据结构的各种解决方案,但我想知道……真的有人这样做过吗?
I love how Backbone thinks about the world. However, there's a lot of coding involved before I get to a proof of concept that has Backbone actually receiving a hierarchical model from a server and updating a tree widget. I've seen there's various solutions for representing deep data structures with Backbone, but I'm wondering... has anyone actually done this?
只要知道这是可能的就会有所帮助.实际上命名树视图 UI 组件和指针以在 Backbone 中使数据分层会更好.一些示例代码会非常棒.
Just knowing that it's possible would be a help. Actually naming the tree view UI component and pointers for making data hierarchical in Backbone would be even better. A bit of sample code would be amazingly fantastic.
就数据大小而言,树将运行 100 多个节点(文件夹)和 1000 多个叶项(文档),并且逐步加载数据(例如,用户单击时一次一个文件夹)会很好in),尽管这可能不是一个亮点.
As far as data size, tree will run 100's of nodes (folders) with low 1000's of leaf items (documents), and it would be nice to progressively load the data (say, one folder at a time as the user clicks in), though that's probably not a showstopper.
谢谢!
推荐答案
如果您不想沿着分层数据集路径移动,一个选项是使用嵌套集 (http://en.wikipedia.org/wiki/Nested_set_model).这允许您将整个集合存储在单个数组(或列表或您想调用的任何名称)中,并使用左"和右"值来确定列表的结构和层次结构.
one option if you don't want to travel down the hierarchical data-set path, is to use a Nested Set (http://en.wikipedia.org/wiki/Nested_set_model). this allows you to store the entire collection in a single array (or list or whatever you want to call it) and use a "left" and "right" value to determine the structure and hierarchy of the list.
如果我没记错的话,这项技术最初是为了优化关系数据库中的数据存储和查询而构建的.但是,我在 C#/Winforms 应用程序中多次使用它,以避免数据的递归层次结构,并且它运行良好.
if i remember right, this technique was originally build to optimize data storage and queries in a relational database. however, i've used it a number of times in C#/Winforms applications, to avoid having a recursive hierarchy of data, and it worked well.
在 javascript 中实现这个应该很容易,但我不知道它在大列表中的表现如何.
an implementation of this in javascript should be pretty easy, but i don't know how well it would perform with a large list.
这篇关于带有树视图小部件的主干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!