简体   繁体   English

为什么我们需要骨干js或任何JS MVC框架?

[英]why do we need backbone js or any JS MVC framework?

Why do we need to use a JS MVC framework(backbone) if we are already using a backend MVC framework(eg Django or ROR). 如果我们已经在使用后端MVC框架(例如Django或ROR),为什么我们需要使用JS MVC框架(骨干)。 I can't understand the concept of two MVC frameworks and how they fit together. 我无法理解两个MVC框架的概念以及它们如何组合在一起。 I thought all front-end related files or logic(html, css, js) come under the views component of the back-end framework. 我认为所有前端相关文件或逻辑(html,css,js)都属于后端框架的views组件。 Can someone explain this in simpler terms? 有人可以用更简单的术语解释这个吗?

Backbone lies in the client [browser], in order to have fast interaction and experience. Backbone位于客户端[浏览器]中,以便进行快速交互和体验。 This way you can take advantage of real-time communication via websockets , or LocalStorage for example. 这样,您可以通过websocketsLocalStorage进行实时通信。

Using a client MVC [MVVM better, in Backbone's case] implies that you just supply a RESTful set of resource from the server [which you can reuse in many other context], and not a full HTML generation stack. 使用客户端MVC [MVVM更好,在Backbone的情况下]意味着您只需从服务器提供RESTful资源集[您可以在许多其他上下文中重用],而不是完整的HTML生成堆栈。

Said that, client side MVC is closer to desktop/mobile UI-oriented MVC implementations [see Cocoa / iOS] than to web-oriented MVC [Symfony, Django, RoR...]. 据说,客户端MVC更接近面向桌面/移动UI的MVC实现[参见Cocoa / iOS]而不是面向Web的MVC [Symfony,Django,RoR ...]。

It's mostly because of scalability, every MV* frameworks allows You to make modular code. 这主要是因为可扩展性,每个MV *框架都允许您制作模块化代码。 To give users high experience by using websites, JS code and some fireworks are necessary. 为了通过使用网站为用户提供高级体验,JS代码和一些烟花是必要的。 JavaScript gives also posibility to relieve backend side from unnecessary computations and because of these simple facts and the scale of currently made websites (huge amount of modules on backend and on frontend side), such MV* JavaScripts frameworks are made and becomes more and more popular. JavaScript还提供了从后端方面免于不必要的计算的可能性,并且由于这些简单的事实和当前制作的网站的规模(在后端和前端方面的大量模块),这样的MV * JavaScripts框架被制作并变得越来越受欢迎。

You may want to look at this post Why use MVVM? 你可能想看看这篇帖子为什么要使用MVVM?

I have been using MVVM and have found it very useful for the front end. 我一直在使用MVVM,并发现它对前端非常有用。 Rendering is much quicker and smoother and view-model binding is done on the client-side. 渲染更加快速和平滑,并且在客户端完成视图模型绑定。

It seems like one of the reasons these JavaScript MVC frameworks started popping was in an effort to to bring some structure to client side JavaScript code. 看起来这些JavaScript MVC框架开始弹出的原因之一是努力为客户端JavaScript代码带来一些结构。 JavaScript has been used more and more in web apps in recent years because it enhances the client side experience so much but when you keep adding more and more, it can quickly become a big cobbled mess of spaghetti code. 近年来,JavaScript在Web应用程序中的使用越来越多,因为它增强了客户端的体验,但是当你不断添加更多时,它很快就会变成一堆乱七八糟的意大利面条代码。 If you've ever inherited a web app that has tons of JavaScript, you know it can take a loooong time to sort through all the callbacks, functions, DOM manipulation, etc. that is going on just to to grasp how to app works and is tied together. 如果您曾经继承过拥有大量JavaScript的Web应用程序,那么您可能需要花费很长时间来对所有回调,函数,DOM操作等进行排序,以便了解如何应用app和捆绑在一起。 It can be really messy. 它可能非常混乱。 These JavaScript MVC frameworks help organize and bring structure too all this code so it doesn't get out of control. 这些JavaScript MVC框架有助于组织和引入所有这些代码的结构,因此它不会失控。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM