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

发布于 2024-12-21 17:11:35 字数 322 浏览 0 评论 0原文

我想开发一个相对简单的应用程序,根据多个输入计算一些值。我不需要后端,所有计算都可以在浏览器中完成。

我对 JavaScript 和 WebApps 有点陌生,我遇到了 Backbone.js

我真的很喜欢 MVC 设计,但是,他们经常提到后端。我的问题:

  • 后端服务器是绝对必要的吗?
  • 后端服务器是可选的,但如果没有后端服务器,主干就没多大意义。
  • 或者骨干真的会帮助我吗?

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.

I really like the MVC design, however, they mention a backend a lot. 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?

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

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

发布评论

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

评论(4

和影子一齐双人舞 2024-12-28 17:11:35
  1. 不需要后端。
  2. 如果您的应用程序不需要后端,Backbone 可以在没有任何后端的情况下完全工作。
  3. 这取决于您的应用程序。如果您想检索某些输入的值并计算结果,那么 Backbone 不会为您做这件事 - 它会帮助您构建代码。如果您的应用程序很简单并且不需要对模型、视图和集合或路由的支持,那么使用 Backbone 就没有意义。很难回答这个问题。

例如:经典 todo 示例应用程序不使用任何后端。

  1. Backend is not required.
  2. Backbone can fully work without any backend if your application doesn't require one.
  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. 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. Hard to answer this question.

For example: Classic todo example application doesn't use any backend.

痴梦一场 2024-12-28 17:11:35

Backbone.js 在模型上实现 fetch()save()destroy() 等方法,自动执行适当的 AJAX 请求并解析响应。因此它通过 REST 服务对后端有强大的支持,但它是可选的。

您仍然可以使用模型、视图、路由器和事件,而无需任何服务器端代码。只是不要调用 REST 方法(或根据您的意愿覆盖它们)。

Backbone.js implements fetch(), save(), destroy() etc. methods on models automatically performing appropriate AJAX requests and parsing response. So it has a strong support for backend via REST services, but it is optional.

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

┈┾☆殇 2024-12-28 17:11:35

您可以使用 localStorage 进行持久化(您必须自己实现它或在网络上找到它,例如 这里),但如果你甚至不需要它,那么你就不需要使用主干中的任何持久性方法。

Backbone 旨在帮助您构建中大型应用程序(js 方面),因此它不会变得难以维护的 jQuery 意大利面。对于简短的应用程序(就 js 而言),除非您想了解主干网的工作原理,否则这确实是一种矫枉过正的做法。

请注意,对于 js 而言,我的意思是客户端代码,如果您有一个巨大的后端,但唯一的 js 是专注于某种形式的东西,它甚至不会算作一个短应用程序(js 方面)。

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.

Backbone is meant to help you structure a medium-large sized application (js-wise), so it doesn't become unmaintainable jQuery spaghetti. With short applications (js-wise) it's really an overkill unless you are trying to learn how backbone works.

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

暗恋未遂 2024-12-28 17:11:35

您可以在没有后端的情况下使用backbone.js。但是,您显然无法存储或检索数据。 Backbone 对于保持代码组织性可能仍然有用,但是当您想要将表示逻辑与操作数据的逻辑分开时(这是 MVC 模式的目标),它确实会发挥作用。通常,您的数据将存储在后端并从后端检索。

如果您想尝试数据持久性,请尝试 backlift.com。 [披露,我在 backlift.com 工作]我们试图让骨干应用程序变得更容易 -并运行,无需设置服务器或处理编译模板。

You can use backbone.js without a backend. 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. 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. [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.

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