使用 MVC 构建对象的分层列表
我想构建一个应用程序,用户在其中以分层方式存储数据,例如使用嵌套的条目列表。 例如
•条目1
•条目2
<前><代码>°subentry1 °子条目2 -子子条目1•条目3
我想知道使用 MVC 模式构建此模型的最佳方法是什么?
我认为每个列表都应该是一个控制器数组,每个条目都是一个模型对象。但列表也有标题!
我的猜测是,List 控制器数组对象应该有两个属性:一个是 Entry 模型对象的标题,另一个是可以在其中存储更多 List 和 Entry 对象的简单数组。
听起来不错吗?
第二点是,如何连接视图对象? Entry 视图和 List 视图对象应该监听鼠标和键盘事件。它们应该使用 ID 系统连接吗?
谢谢
PS:顺便说一句,我使用 sproutcore javascript 框架来构建我的应用程序。但我想让讨论保持不可知且开放的状态。
I want to build an application in which the user store data in a hierarchical way, for example using nested lists of entries.
for example
•entry1
•entry2
°subentry1 °subentry2 -subsubentry1
•entry3
I was wondering which would be the best way to build this using an MVC pattern
I suppose that every list should be a controller array and every entry is a model object. but a list also has a title!
My guess is that the List controller array object should have two property: a title that is an Entry model object and a simple array in which you can store more List and Entry objects.
Sounds right?
the second point is, how do i connect the view objects? the Entry view and the List view objects should listen mouse and keyboard events. should they be connected using an id system?
Thanks
PS: btw i using sproutcore javascript framework to build my app. But i would like to leave the discussion as agnostic and open is possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白为什么 MVC 对这个问题有任何影响。您所谈论的只是数据建模。在确定如何存储它之后,您可以实现实际显示它的方式,但在此阶段不必担心 MVC。
无论如何,快速回答将使您能够更深入地研究哪种解决方案最适合您的用例。
我完全赞成使用 Nested Set 来对层次数据进行建模,就像您刚才提到的那样,但我也倾向于同时运行 Adjanceyc List,因为我发现查询我的数据结构更容易。
除非我完全误解了你的问题,否则我不明白为什么 MVC 会参与其中。
I don't see why MVC has any impact on this question. All you are talking about is modelling the data. Your implementation fo how you actually display it can come up after you have determined how you will store it, but don't worry yourself with MVC at this stage.
Anyway, a quick answer and will leave you to research in greater depth which solution fits your use case best.
I'm all for favoring Nested Set for modeling heirarchical data like you just mentioned, but I tend to also run Adjanceyc List alongside it, cause I find it easier to then interrogate my data structures.
Unless I totally misunderstoof your question, I don't understand why MVC is involved in this.