Javascript MVC 框架和服务器端框架 [英] Javascript MVC Frameworks and Server Side Frameworks

查看:25
本文介绍了Javascript MVC 框架和服务器端框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于两个 MVC 框架的共存(在客户端和服务器端).

This question is regarding the co-extisense of two MVC Frameworks (on the client side and the server side).

一些背景:我对 Web 开发还很陌生,但我是一名非常熟练的程序员.我最近才学习 javascript 和 Django.我的应用程序的前端是相当广泛的 Javascript,因此我决定使用一个框架.我目前正在阅读可用的框架,并且倾向于使用backbone.js + jquery.

Some Background: I am fairly new to web development, but am a very proficient programmer. I learnt javascript and Django only recently. The Front end for my app is quite Javascript extensive and hence I decided to use a framework. I am currently reading up on the available frameworks and I am inclining towards backbone.js + jquery.

我的问题是我不完全理解像backbone.js这样的MVC框架如何与像Django这样的服务器端框架共存.

My problem is that I don't fully understand how a MVC framework like backbone.js can co-exist with a server side framework like Django.

据我对backbone.js的理解,当模型发生变化时,模型相关的相应视图会自动更新.在这里,我们指的是客户端框架的视图",对吗?这样的视图"会与后端框架的控制器"通信吗?

From what I understood of backbone.js, when there is a change to a model, the corresponding views related to the model are automatically updated. Here, we are referring to the "views" of the Client side framework right? Would such a "view" communicate with the backend framework's "controller"?

可能的目录结构是怎样的?这样的架构不好吗?

How would a possible directory structure be? Is such an architecture bad?

这个问题有意义吗?还是我迷路了?

Does the question make sense? or am I lost?

为了增加一些清晰度:我想我的基本问题是:如何在客户端构建复杂的单页 JS Web 应用程序(特别是如果您使用的是客户端框架))?具体来说,我很好奇如何根据模型对象、UI 组件、任何控制器和处理服务器持久性的对象来清晰地构建应用程序.

To add some clarity: I guess my essential question is : How a complex single-page JS web application be structured on the client-side (espertially if u are using a client side framework)? Specifically I'm curious about how to cleanly structure the application in terms of its model objects, UI components, any controllers, and objects handling server persistence.

推荐答案

我可以用 Rails/Backbone 说话,但我无法想象 Django 会有多大不同.

I can speak in terms of Rails/Backbone, but I can't imagine that Django would be much different.

首先,像 Backbone 这样的客户端 MVC 框架不仅仅适用于单页应用程序.您还可以使用它为更传统的应用程序的一个或多个视图添加一些丰富的交互.它们只是在客户端提供结构和数据抽象.

First, a client-side MVC framework like Backbone isn't just for single-paged apps. You can also use it to add some rich interaction to one or many views of a more traditional app. They simply provide structure and data abstractions on the client.

接下来,这些客户端框架专门设计用于与您的后端 MVC 框架配合使用.Backbone.js(因为你专门标记了它)模型和集合与 REST 服务一起工作.它们将通过 GET/POST/PUT/DELETE 动词进行对话,并最终在它们发出异步请求时与后端的控制器进行通信.

Next, these client-side frameworks are designed specifically to work with your back-end MVC frameworks. Backbone.js (since you tagged it specifically) models and collections work with REST services. They will talk via GET/POST/PUT/DELETE verbs and will ultimately communicate with your controllers on the back-end when they make asynchronous requests.

在 Backbone 的情况下,它使用 JSON 而不是 HTML.在 Rails 的情况下,这在控制器中真的很容易处理.如果请求是 HTML 请求,那么您将视图作为 HTML 返回.如果是 JSON 请求(*.json 或 Content-type),则控制器返回数据的 JSON 表示.我假设在 Django 和 Rails 中让同一个控制器响应多个内容请求(HTML、XML、JSON 等)一样容易

In the case of Backbone, it talks JSON instead of HTML. In the case of Rails, this is really easily handled in the controller. If the request is an HTML one, then you return a view as HTML. If it is a JSON request (*.json or Content-type) then the controller returns a JSON representation of the data. I am assuming that it is as easy in Django as it is in Rails to have the same controller respond to multiple content requests (HTML, XML, JSON, etc)

这篇关于Javascript MVC 框架和服务器端框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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