您对骨干.js项目的最佳实践是什么? [英] What are your best practices for backbone.js projects?

查看:74
本文介绍了您对骨干.js项目的最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我一直关注骨干.js已有几个月,并通过大量教程工作,但我对骨干(或有关它的技能)仍然没有足够的信心,无法在更大的项目中使用它.

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.

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

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).

因此,我想了解您的ribs.js最佳做法/食谱?您如何处理嵌套的集合/视图? JSON序列化?模型之间更复杂的查询?

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?

推荐答案

以下是您似乎已经提出的问题列表:

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

backbone.js最佳做法/食谱
我的第一习惯/秘诀是深入研究 backbone.js代码并阅读它,甚至可以使用js调试器逐步调试它.该代码有据可查,是现代JS代码应有的典范.

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.

您如何处理嵌套的集合/视图?
Afaik没有简单的方法"来处理嵌套集合和处理子集合中发生的事件.您必须实现它.不过,我还不必处理集合的集合,因此也许您可以通过重组数据模型"来避免这种情况.本身具有模型集合的模型可以满足嵌套模型的大部分要求.

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序列化
你有什么问题?骨干文档说:强烈建议包含json2.js"

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

模型之间的关系
同样,您正在实现模型.您的模型可以包含其他模型.您如何与他们合作以及如何互动取决于您自己.以我的经验,并不需要在javascript中复制后端数据模型.您的前端模型很可能会比后端模型更简单.

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.

模型继承
通过使用骨干.js,您已经在使用模型继承.这就是您编写 var MyModel = Backbone.Model.extend ...

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

很抱歉,我们没有详细介绍,但是就像托马斯·戴维斯(Thomas Davis)所说的那样,问题很模糊.您将获得一个更详细的问题的更详细答案,该问题描述了您遇到的特定问题.

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.

这篇关于您对骨干.js项目的最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆