你的backbone.js项目的最佳实践是什么?

发布于 2024-10-29 02:11:38 字数 227 浏览 2 评论 0 原文

尽管我关注backbone.js 已经有几个月了,并且学习了大量教程,但我仍然对在更大的项目中使用backbone(或我的相关技能)没有足够的信心。

我的经验是,backbone.js 教程的质量差异很大,有些已经过时了(尤其是backbone 文档中的示例待办事项应用程序)。

所以我想了解一下你们的backbone.js 最佳实践/秘诀?如何处理嵌套集合/视图? JSON 序列化?模型之间的查询更复杂?

Although I'm following backbone.js for some months and worked through a plethora of tutorials, I'm still not confident enough in backbone (or my skills regarding it) to use it in a larger project.

My experience is that the backbone.js tutorials vary greatly in quality, some are terribly outdated (especially the sample todo app from the backbone docs).

So I'd like to know about your backbone.js best practices/recipes? How do you handle nested collections/views? JSON serialisation? More complex queries between models?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

爱要勇敢去追 2024-11-05 02:11:39

由于这个问题的答案可能太长,而且由于它的一般范围,我将把这些链接留在这里。我希望他们能帮助其他发现这个问题的人,因为他们帮助我更好地理解这个框架并拥有更好的应用程序,有效地利用内存,更好地组织文件以及更具可读性和可维护性的代码:

http://ricostacruz.com/backbone-patterns/

http://kilon.org/blog/2012/11/3-tips-for -writing-better-backbone-views/

http://blog.involver.com/2012/01/26/testing-backbone-js-best-practices-2/

http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing -page-transitions-in-backbone-apps/ (过时的解决方案,但阅读和理解非常重要!!)

https://github.com/thomasdao/Backbone-View-Manager

我希望我从一开始就拥有这个。

干杯!

Since the answer for this question might be too long, because of the general scope it has, I'll leave these links here. I hope they will help some other people who find this question, as they helped me to have a better understanding of this framework and have a better application, with an efficient use of memory, a better organization of files and a more readable and maintainable code:

http://ricostacruz.com/backbone-patterns/

http://kilon.org/blog/2012/11/3-tips-for-writing-better-backbone-views/

http://blog.involver.com/2012/01/26/testing-backbone-js-best-practices-2/

http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/ (out of date solution but really important to read and understand!!)

https://github.com/thomasdao/Backbone-View-Manager

I wish I had this from the beginning.

Cheers!

海未深 2024-11-05 02:11:39

我认为这些问题有点模糊,无法在简单的帖子中回答。

我即将完成在 Backbone.js 中完成的完整 Web 应用程序,并且还想讨论这些最佳实践,以便我可以在发布之前快速修改一些选择。

我目前正在backbonetutorials.com 上工作,尝试最终将这些较难的问题组合在一起。

保存馆藏的解决方案可能是第一个问题,但如果有一些社区参与,那就太棒了。

I think the questions are a bit vague to be answered in a simple post.

I am nearing completion of a full web app done in Backbone.js and would also like to discuss these best practices so I can revise some choices quickly before launch.

I am working on backbonetutorials.com at the moment to try group these harder questions together eventually.

Solutions to saving collections will probably be the first question but would be awesome if there was some community engagement.

淡忘如思 2024-11-05 02:11:39

在开发基于 Backbone.js 的应用程序时,您可以处理很多事情。例如:

  1. 自定义插件和混合
  2. 嵌套视图/子视图
  3. 部分视图更新
  4. 模板管理 - 存储、前端和后端预编译
  5. 序列化模型
  6. 关系数据模型
  7. 使用事件调度程序
  8. 子路由
  9. 大规模应用程序架构等。

还有更多概念对于开发基于 Backbone.js 的单页应用程序至关重要。您可以尝试我的书Backbone.js 模式和最佳实践 详细讨论了所有这些要点。

There are a number of things that you can take care of while developing Backbone.js based applications. For example:

  1. Custom plugins and mixins
  2. Nested views/Sub views
  3. Partial view updating
  4. Template management - Storing, Pre-compiling at front end and back end
  5. Serializing models
  6. Relational data model
  7. Using Event dispatcher
  8. Subrouting
  9. Large scale application architecture etc.

There are lot more concepts which are essential for developing single page Backbone.js based applications. You can try out my book Backbone.js Patterns and Best Practices which discusses all these points in detail.

纵性 2024-11-05 02:11:38

以下是您似乎问过的问题列表:

backbone.js 最佳实践/食谱
我的第一个实践/秘诀是深入研究 backbone.js 代码 并阅读甚至可以使用 js 调试器单步执行它。该代码有很好的文档记录,是现代 JS 代码的一个很好的例子。

如何处理嵌套集合/视图?
据我所知,没有“简单的方法”来处理嵌套集合和处理子集合中发生的事件。你必须实施它。不过,我还没有处理过集合的集合,所以也许您可以通过重组您的“数据模型”来避免它。本身具有模型集合的模型可以满足嵌套模型的大部分要求。

就视图而言,您基本上可以控制它们的渲染方式。骨干网提供的视图只不过是一种将相应模型中的更改更改为渲染代码的机制。您实现渲染。因此,如果您想要嵌套视图,您可以使用支持部分的模板引擎(如果我正确理解嵌套视图的含义)。

JSON 序列化
你的问题是什么?主干文档说“强烈建议包含 json2.js”

模型之间的查询更复杂?
再说一遍,你的问题是什么? Backbone 为您提供了做自己事情的结构,您必须自己实现复杂性

模型之间的关系
同样,您正在实施模型。您的模型可以包含其他模型。你对他们做什么以及如何互动都取决于你。根据我的经验,没有必要在 JavaScript 中复制后端数据模型。您的前端模型很可能会比后端模型更简单。

模型继承
通过使用backbone.js,您已经在使用模型继承。这就是当您编写 var MyModel = Backbone.Model.extend... 时发生的情况,

抱歉没有详细说明,但就像 Thomas Davis 所说,问题非常模糊。对于描述您遇到的具体问题的更详细的问题,您将获得更详细的答案。

Here is a list of questions you seem to have asked:

backbone.js best practices/recipes
My number one practice/recipe is to dive into the backbone.js code and read it, step through it with js debugger even. The code is well documented and is an excellent example of what modern JS code should be.

How do you handle nested collections/views?
Afaik there is no "simple way" to handle nested collections and handling events that happen in a sub-collection. You'd have to implement it. I haven't had to deal with a collection of collections yet though, so maybe you can avoid it by restructuring your "data model". A model that has a collection of models in itself satisfies most of the requirement of a nested model.

As far as views go, you're basically in control how they get rendered. A view as provided by backbone is nothing but a mechanism to get changes in corresponded model to your render code. You implement the rendering. So if you want nested views, you can use template engine that supports partials(If i understand correctly what you mean by nested views).

JSON serialisation
Whats your question? The backbone doc says "it's highly recommended to include json2.js"

More complex queries between models?
Again, whats your question? Backbone provides you structure to do your own thing, you have to implement the complexities yourself

Relations between models
Again, you are implementing the models. Your models can contain other models. What you do with them and how you interact is up to you. In my experience its wasn't necessary to replicate the backend data model in javascript. Its quite possible that your front-end models will be simpler than the backend ones.

Model inheritance
By using backbone.js you are already using model inheritance. This is what happens when you write var MyModel = Backbone.Model.extend...

Sorry for not going into more detail, but like Thomas Davis said, the questions were very vague. You'd get more detailed answer on a more detailed question describing a specific problem you're having.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文