Combining Serverside MVC with Backbone.js

I use .NET MVC for all my serveride logic and serve the source pages, but my application is very heavy on the client side, so I adopted Backbone.JS, which is very useful.

I'm not sure how to architect my system to incorporate both technologies. As I can see, I have two options

  • Reset the β€œV” from the MVC on the server side, return the JSON data to the client on pageload and use the basic client templates to create a graphical interface from the basic JSON / Backbone models.

  • Bring back the original pages from a server fully mapped to .NET MVC. Also, return the data that was used to display it, and call the collection.reset ({silent: true}) method to bind returned the data to the view. Do I think that this will be correct, let me subsequently make changes to the use of add / remove / change handlers on views?

1 Confuses me, because I'm afraid to let go of any part of the server-side MVC where my main skill lies.

2 I am confused because I am interested in the fact that I can present risk and work using two different rendering methods on the client server.

What is the correct way to combine server side MVC with backbone.js 1 or 2 or some other way?

+6
source share
2 answers
  • You really won't break V , you just change its presentation from HTML to JSON. You are worried that you feel more comfortable with the server-side materials, and this is really not an urgent problem ... you will do everything you need to do and study / create Javascript templates during your work.

  • This is one way to do this, and it really helps if you need a disabled javascript reserve or you are tied to accessibility recommendations. The part that you are missing is that you will have to redisplay the page after loading it to attach your models to the DOM elements. Alternatively, you can use a tool that handles this mapping for you, but you will have to weigh this additional complexity yourself.

In using a career framework, we are not required to support scripts without javascript scripts, and so we just upload the + js templates to bootstrap, and then let the router take over and use something more similar to your first idea, since it seems like you just getting started, the biggest thing that really helped us move was that it’s easier to make changes to your model and then let your views subscribe to model change events (and not vice versa).

+4
source

I don't know what the Accepted Way is, but I found it problematic to combine V from the server side, and then weaving Backbone (etc.). In very controlled situations, this may work, but if your application is very heavy on the client side, my suggestion would be to forget about server-side rendering and just return JSON and let Backbone handle the rendering of your content using some kind of templates (Mustache, etc. d.).

Yes, you have full control over Backbone events, so you will have a pen to do what you want.

I heard you give up part of your server-side skill set. I was the same, but if this is what your project is calling for, I think it will be easier for you to allow server-side rendering.

Good luck

+1
source

Source: https://habr.com/ru/post/913430/


All Articles