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

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

问题描述

这问题是关于2 MVC框架的共同extisense(在客户端和服务器端)。

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应用程序可以在客户端(espertially如果u使用的客户端框架结构)?具体来说,我很好奇如何在它的模型对象,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.

推荐答案

我可以在轨道/骨干网方面讲,但我无法想象,Django的将是很大的不同。

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

首先,像骨干客户端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.

在主干的情况下,它谈到的HTML JSON来代替。在Rails的情况下,这实在是很容易在控制器处理。如果请求的是一个HTML的,那么你就返回一个HTML格式下查看。如果它是一个JSON请求(*以.json或内容类型),那么控制器返回数据的一个JSON重新presentation。我假设它是在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天全站免登陆