哪种 Javascript 框架最适合这种情况?
我想用js构建一个联系人列表,但是js技术太多了,比如backbone.js、spine.js、knockout.js等,我真的不知道哪一种最适合我。
我的联系人有几个总体类型:FacebookUser、User 和 UserList。 userlist 的特点是它是用户或 UserList 的集合。此外,它本身可能有也可能没有自己的联系信息(如公司或团队)。
我想在树视图中显示此列表,您可以在其中深入了解 UserList (并延迟加载组成员)。
最后,整个联系人列表是一个实例。我的意思是,您一次在同一个窗口中打开 0-n 个联系人列表。
对于这种情况我应该使用什么框架?
I want to build a contact list in js, but there are so many js technologies like backbone.js, spine.js, knockout.js, etc. that I dont really know which one is best for me.
My contacts have a few overarching types: FacebookUser, User, and UserList. The catch with userlist is that it is a collection of users or UserLists. Furthermore, it itself may or may not have its own contact information (like a company or a team).
I want to display this list in a tree-view where you can drill down into UserList (and have the group members lazy loaded).
Lastly, the entire contact list is an instance. What I mean is that you have have 0-n number of contact lists open in the same window at a time.
What framework should I use for this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您提到的所有三个库(backbone.js、spine.js、knockout.js)都针对单页浏览器应用程序。
但您对问题的描述听起来更像是格式问题,而不是数据管理问题。即,您希望页面显示数据。您不需要将页面的更改保存回服务器;您的用户将刷新页面以显示新的或不同的信息。
如果我对你的目标的理解是正确的,我会选择 jQuery 或 YUI。你提到的库太过分了。
添加 YUI 有一个很好的 treeview 小部件,支持分支的延迟加载。我用它来实现这个目的。
如果您决定使用模型层,YUI 3 包括 模型 和 模型列表。它们基于 Backbone api。
回复:MVC 评论 在评论中,OP 提到“同一数据的多个视图、更改传播、编辑检测(如果用户更改数字)以及来自服务器的更新”
对于这些情况,是的,现在许多酷孩子都在浏览器本身上使用完整的 MVC 框架。如果您想朝这个方向发展,那么您可以使用您提到的三个中的任何一个。注意:
Backbone(可能还有其他两个)不提供完整的 MVC。相反,Backbone 提供模型和模型。控制器部分,尤其是模型。通常使用 Mustache 作为视图。此外,通常使用下划线或 jQuery 来提供基本功能。如果您通过 Google 搜索骨干示例,您会发现其中许多都包含 jQuery。
查看 YUI 新 y.App。它在一个文档齐全的库中包含所有 MVC 部分。 y.App 正在火热开发中,基于 Backbone api。 video-cast
MVC 框架浏览器是全新的。不要对快速更改的库代码、不一致的文档、很少的示例等感到惊讶。您还应该考虑记录和发布您的调查。为了获得额外的积分,让它在移动浏览器上运行良好。
传闻 49 Signals 正在开发浏览器端 MVC 框架,但我们还没有看到任何消息。
传闻
我相信backbone是模型库中最高级的。但事实证明,它让许多新用户感到困惑,因此其他一些基于其概念的库。
All three of the libraries that you mention (backbone.js, spine.js, knockout.js) are aimed at single-page browser apps.
But your description of your problem sounds more like a formatting issue, not data management. Ie, you want your page to show the data. You don't need to save changes from your page back to the server; your users will refresh to the page to show new or different information.
If my understanding of your goal is correct, I'd go with jQuery or YUI. The libs you mention would be overkill.
Added YUI has a nice treeview widget that supports lazy-loading of branches. I use it for that.
If you do decide to use a model layer, YUI 3 includes Model and ModelList. They're based on Backbone api.
Re: MVC comment In a comment, the OP mentions "multiple views on the same data, change propagation, and edit detection (if a user changes a number) and updates from the server"
For those cases, yes, these days many cool kids are using a complete MVC framework on browser itself. If you wish to go in that direction, then you could use any of the three you mentioned. Notes:
Backbone, and probably the other two, do not provide complete MVC. Rather, Backbone supplies the Model & Controller portions, especially the Model. It is common to use Mustache for the View. In addition, it is common to use underscore or jQuery to supply basic facilities. If you Google for backbone examples, many of them include jQuery.
Checkout YUI new y.App. It includes all of the MVC parts in one well documented lib. y.App is in hot development and is based on the Backbone api. A video-cast
MVC Frameworks on the browser are brand new. Don't be surprised by quickly changing library code, inconsistent docs, few examples, etc. You should also consider documenting and posting your investigations. For extra credit, get it working well on mobile browsers.
49 Signals was rumored to be working on a browser-side MVC framework, but we haven't seen anything yet.
I believe that backbone is the most senior of the Model libraries. But it has proven to be confusing to many new users, hence some of the other libs based on its concepts.
Based on my experience with YUI, their Y.app will have the most consistent and complete api set and the best docs.
如果我们考虑您的具体情况,我会强烈选择 Knockout.js
Knockout 是为 UI 构建的,即您的数据模型可以绑定到 HTML 元素,然后模型中的任何更改都会相应地操作 UI。
在您的情况下,联系人列表的添加/删除将由 Knockout 自动处理。您所需要的只是定义如何处理树视图中的更改(通过代码或 HTML 模板),Knockout 会处理这个问题。
也就是说,定义联系人列表的树视图仍然是完全不同的任务,您可能需要为此使用一些 CSS/JS 库。
If we take your specific case, I would strongly go for Knockout.js
Knockout is built for UI i.e. that your data model can be binded to HTML elements and then any changes in the model manipulate the UI accordingly.
In your case the additions/deletions to the contact list will be automatically tackled by Knockout. All you need would be to define the how the changes in the tree view are to be tackled (either by code or by HTML templates) and Knockout will take care of that.
Saying that, defining the treeview of your contact list is still different task altogether and you may need to you use some CSS/JS library for that.