使用 Backbone.js 时是否必须使用后端?
我想开发一个相对简单的应用程序,根据多个输入计算一些值。我不需要后端,所有计算都可以在浏览器中完成。
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
例如:经典 todo 示例应用程序不使用任何后端。
For example: Classic todo example application doesn't use any backend.
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).
您可以使用 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).
您可以在没有后端的情况下使用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.