结合Serverside集团MVC与Backbone.js的 [英] Combining Serverside MVC with Backbone.js

查看:145
本文介绍了结合Serverside集团MVC与Backbone.js的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用.NET MVC我所有的服务器端逻辑,并提供了初始页面,但我的应用程序是在客户端,所以我已经通过了已经被证明是非常有用的Backbone.js的很重。

我不确定建筑师怎么我的系统,虽然二者结合的技术。在路上我看到它,我有两个选择


  1. 废钢MVC在服务器端的'V',返回JSON数据到
    在页面加载和使用主干客户方模板客户建立
    从基部的JSON /骨干模型的图形用户界面。


  2. 从.NET MVC完全渲染服务器返回初始页面。
    也返回的是使用以使它们并调用的数据
    collection.reset({沉默:真})方法连接起来,
    返回的数据的图。我是正确的思维,这将
    请允许我随后更改使用添加/删除/修改
    对意见的处理程序?


1麻烦我,我怕让服务器端的MVC,的任何一部分去其在我的核心技能所在。

2麻烦我,我担心我可能会通过让客户端服务器上的两个不同的渲染方法引入风险和工作。

请告诉我到服务器端MVC与Backbone.js的1或2或其他方式相结合的正确方法?


解决方案

  1. 您是不是真的杀 V ,你只是改变其重新$ P $从HTML psentation到JSON。你遇到困难,因为你感觉更舒服与服务器端的东西,这不是一个真正的有效的关注......你会得到做需要做的事情,并学会/你去创建JavaScript的模式是什么。


  2. 这是做到这一点的一种方式,它真的帮助,如果你需要禁用JavaScript回退,或者你通过易用性原则的约束。你缺少的部分是,你将不得不重新呈现页面,一旦它的加载到你的模型附加到DOM元素。另外,您可以使用工具处理这个映射你的,但是这增加了复杂性,你必须权衡了自己。


在骨干人才招聘使用,我们不一定要支持javascript少的情况,而我们,所以我们只加载初始加载模板+ JS,则让路由器接管和使用的东西更像是你的第一个想法。因为它听起来像你刚刚起步,最重要的事情,让我们能真正得到感动是意识到它的办法容易更改您的模型,然后让你的看法订阅模式的转变事件(而不是周围的其他方法)。

I'm using .NET MVC for all my serverside logic and serving out initial pages, but my application is very heavy on the client-side so I have adopted Backbone.JS which is proving to be very useful.

I'm unsure how to architect my system to incorporate both technologies though. The way I see it I have two options

  1. Scrap the 'V' from MVC on the server-side, return JSON Data to the client on pageload and use backbone clientside templates to build up the GUI from the base JSON/Backbone Models.

  2. Return the initial pages from the server fully rendered in .NET MVC. Also return the data that was used to render them and call the collection.reset({silent: true}) method to link up the returned data to the view. Am I right in thinking that this will allow me to subsequently make changes to using the add/remove/change handlers on the views?

1 Troubles me as I'm afraid of letting go of any part of server-side MVC, its where my core skill lies.

2 Troubles me as I'm concerned I might be introducing risk and work by having two different rendering methods on client server.

Whats the correct way to combine Server-side MVC with backbone.js 1 or 2 or some other way?

解决方案

  1. You are not really scrapping the V, you're just changing it's representation from HTML to JSON. You are troubled because you feel more comfortable with the server side stuff, and that's not really a valid concern... you'll get done what needs to be done, and learn/create the Javascript patterns as you go.

  2. This is one way to do it, and it really helps if you need a javascript disabled fallback or you're bound by accessibility guidelines. The part you're missing is that you will have to re-render the page once it's loaded to attach your models up to the DOM elements. Alternatively you could use a tool that handles this mapping for you, but that's added complexity you'll have to weigh out yourself.

In the Careers usage of backbone, we are not bound to support javascript-less scenarios, and we so we just load the templates + js on the initial load, then let the router take over and use something more like your first idea. Since it sounds like you're just getting started, the biggest thing that helped us really get moving was realizing that it's way easier to make changes to your model and then let your views subscribe to model change events (instead of the other way around).

这篇关于结合Serverside集团MVC与Backbone.js的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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