简体   繁体   English

使用Backbone.js时是否必须使用后端?

[英]Do I have to use a Backend when using Backbone.js?

I want to develop a relatively simple application that calculates some value based on several inputs. 我想开发一个相对简单的应用程序,根据几个输入计算一些值。 I dont want a backend, all the calculation can be done in the browser. 我不想要后端,所有的计算都可以在浏览器中完成。

Im a little new to JavaScript and WebApps and I came across Backbone.js . 我是JavaScript和WebApps的新手,我遇到了Backbone.js

I really like the MVC design, however, they mention a backend a lot. 我非常喜欢MVC设计,但他们提到了很多后端。 My question: 我的问题:

  • Is a backend server absolutely required? 绝对需要后端服务器吗?
  • Is a backend server optional but without one there isn't much point in backbone. 后端服务器是可选的,但没有一个在骨干网中没有多少意义。
  • Or will backbone will really help me out? 或者骨干会真的帮助我吗?
  1. Backend is not required. 后端不是必需的。
  2. Backbone can fully work without any backend if your application doesn't require one. 如果您的应用程序不需要,Backbone可以在没有任何后端的情况下完全工作。
  3. That depends on your application. 这取决于您的申请。 If you want to retrieve value of some inputs and calculate a result then Backbone won't do that for you - it will help you structure your code. 如果您想检索某些输入的值并计算结果,那么Backbone将不会为您执行此操作 - 它将帮助您构建代码。 If you app is simple and don't need support for models, views and collections or routing, then there is no point in using Backbone. 如果您的应用程序很简单,并且不需要对模型,视图和集合或路由的支持,那么使用Backbone是没有意义的。 Hard to answer this question. 很难回答这个问题。

For example: Classic todo example application doesn't use any backend. 例如:Classic todo示例应用程序不使用任何后端。

Backbone.js implements fetch() , save() , destroy() etc. methods on models automatically performing appropriate AJAX requests and parsing response. Backbone.js在模型上实现fetch()save()destroy()等方法,自动执行适当的AJAX请求和解析响应。 So it has a strong support for backend via REST services, but it is optional. 因此它通过REST服务强烈支持后端,但它是可选的。

You can still use models, views, routers and events without any server-side code. 您仍然可以使用模型,视图,路由器和事件,而无需任何服务器端代码。 Just don't call REST methods (or override them at your wish). 只是不要调用REST方法(或根据自己的意愿覆盖它们)。

You can use backbone.js without a backend. 您可以在没有后端的情况下使用backbone.js。 However you obviously won't be able to store or retrieve data. 但是,您显然无法存储或检索数据。 Backbone may still be useful for keeping your code organized, however it really shines when you want to separate presentation logic from logic that manipulates your data, which is a goal of the MVC pattern. Backbone可能仍然有助于保持代码的有序性,但是当您想要将表示逻辑与操纵数据的逻辑分开时,它确实很有用,这是MVC模式的目标。 Generally your data will be stored on and retrieved from a backend. 通常,您的数据将存储在后端并从后端检索。

If you want to play around with data persistence, try out backlift.com . 如果您想玩数据持久性,请试试backlift.com [disclosure, I work on backlift.com ] We've tried to make it easy to get a backbone app up-and-running without having to setup a server or deal with compiling templates. [披露,我在backlift.com上工作]我们试图让骨干应用程序运行起来很容易,而无需设置服务器或处理编译模板。

You can use localStorage for persistence (you'd have to implement this yourself or find it on the web, like here ) but if you don't even need that then you don't need to use any of the persistence methods in backbone. 您可以使用localStorage进行持久化(您必须自己实现或在Web上找到它,如此 )但如果​​您甚至不需要,那么您不需要使用主干中的任何持久性方法。

Backbone is meant to help you structure a medium-large sized application (js-wise), so it doesn't become unmaintainable jQuery spaghetti. Backbone旨在帮助您构建一个中型大型应用程序(js-wise),因此它不会成为不可维护的jQuery意大利面。 With short applications (js-wise) it's really an overkill unless you are trying to learn how backbone works. 对于简短的应用程序(js-wise),除非你试图了解骨干是如何工作的,否则它实在是太过分了。

Note with js-wise I mean the client side code, if you had a huge backend but the only js would be something that focuses some form, it would not even count as a short application (js-wise). 注意js-wise我的意思是客户端代码,如果你有一个巨大的后端,但唯一的js会聚焦某种形式,它甚至不会算作一个简短的应用程序(js-wise)。

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

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