简体   繁体   English

js mvc库如spine,backbone,jsmvc如何集成到基于服务器的MVC框架,如锂或zend?

[英]How do js mvc libraries like spine, backbone, jsmvc integrate into a Server based MVC framework like lithium or zend?

My specific question is that I would like links to references so that I can learn/research the question title, not spark a debate about the features or which one is better. 我的具体问题是,我希望链接到参考文献,以便我可以学习/研究问题标题,而不是引发关于特征或哪个更好的争论。 I have found jsMVC , spine , and EJS but am not familiar with what place they hold in the MVC pattern. 我找到了jsMVCspineEJS,但我不熟悉它们在MVC模式中的位置。 Aren't they basically just views themselves since they handle rendering ? 它们不是基本上只是自己查看自己处理渲染吗? so does that mean a client MVC is like a sub pattern with the V of the server MVC ? 这是否意味着客户端MVC就像是服务器MVC的V的子模式? Links that provide background and theory on how these client side libraries work inside/with a traditional server side framework would be helpful. 提供有关这些客户端库如何在内部/与传统服务器端框架一起工作的背景和理论的链接将是有帮助的。

Thanks! 谢谢!

As I was writing this I read this answer and this type of answer helps, more like it with reference links would be great. 在我写这篇文章时,我读到了这个答案这种答案有所帮助,更像是参考链接会很棒。

Client side MVC can handle the entire MVC stack. 客户端MVC可以处理整个MVC堆栈。 If your using both server and client side MVC then your duplication your models and routes. 如果您同时使用服务器端和客户端MVC,那么您的模型和路由将重复。

Client side MVC basically allows you to bridge your server and client together. 客户端MVC基本上允许您将服务器和客户端连接在一起。 Why should your server send views? 您的服务器为什么要发送视图? Why not send the model as json and load it into a client side model and have the client render that view. 为什么不将模型作为json发送并将其加载到客户端模型中并让客户端呈现该视图。

You can even go further with the routing. 您甚至可以进一步了解路由。 Why have the routing handled by the server? 为什么服务器处理路由? The client can do this. 客户端可以这样做。 Just allow the client access to your RESTful database and you don't need any serverside MVC. 只允许客户端访问您的RESTful数据库,您不需要任何服务器端MVC。

Of course if you want to support non-javascript then you need server side MVC. 当然,如果你想支持非JavaScript,那么你需要服务器端MVC。

Personally I use a heavy client / heavy server setup. 我个人使用重型客户端/重型服务器设置。 I use the entire serverside mvc for the first page load. 我使用整个服务器端mvc进行首页加载。 From then on the client upgrade itself to only use clientside MVC if it can with javascript. 从那时起客户端升级到只使用客户端MVC,如果它可以使用javascript。 If it can't it continues to use serverside MVC. 如果它不能继续使用serveride MVC。

This kind of development is made a lot easier by having SSJS so your models, collections and views are a shared codebase and only maintained in one place. 通过使用SSJS可以使这种开发变得更加容易,因此您的模型,集合和视图是共享代码库,并且只在一个地方维护。

Utilizing a client-side MVC framework can be useful for code organization when dealing with very large, Ajax-reliant applications. 在处理非常大的,依赖于Ajax的应用程序时,利用客户端MVC框架对代码组织非常有用。 Consider a client-side Model layer that consistently talks to one or more services provided by individual applications in a Service-Oriented Architecture. 考虑客户端模型层,该层始终与面向服务的体系结构中的各个应用程序提供的一个或多个服务进行通信。 The individual service providers may implement their services with an MVC or not, but there's an advantage in having client-side Models to consume that data. 各个服务提供商可以使用MVC来实现他们的服务,但是使用客户端模型来消费这些数据是有利的。

Keep in mind, too, that Javascript frameworks - whether jQuery, Mootools, Node.js - are going to implement an event-driven control workflow, where a single event can trigger callbacks that cascade into other callbacks. 请记住,Javascript框架 - 无论是jQuery,Mootools,Node.js - 将实现事件驱动的控制工作流,其中单个事件可以触发级联到其他回调的回调。 Typically on the server-side, at least where the HTTP request-response cycle is concerned, we want to create discrete, atomic tasks that generate a quick and redictable response and may trigger or enqueue some other asynchronous event on the server, because the response is blockking the user from making another request and continuing his workflow. 通常在服务器端,至少在涉及HTTP请求 - 响应周期的地方,我们希望创建离散的原子任务,这些任务生成快速且可重复的响应,并可能触发或排队服务器上的其他异步事件,因为响应阻止用户发出另一个请求并继续他的工作流程。 Not so for client-side Javascript. 客户端Javascript不是这样。

Adding a full client-side MVC to the stack when you're already utilizing a MVC framework server-side can be overkill and may lead to a duplication of effort. 当您已经在使用MVC框架服务器端时,将完整的客户端MVC添加到堆栈可能会过度,并可能导致重复工作。 It can be done correctly. 它可以正确完成。 Specialize your server-side code into access control and CRUD operations, returning JSON instead of HTML views. 将服务器端代码专门化为访问控制和CRUD操作,返回JSON而不是HTML视图。 Specialize your client-side code into view processing and event handling using light-weight models expecting a JSON data store with conventional, ReST-ful routing. 使用轻量级模型将您的客户端代码专门用于视图处理和事件处理,期望JSON数据存储具有传统的ReST-ful路由。 Use them for what they're both good for to get the most mileage. 使用它们可以获得最大的里程数。

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

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