Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should be the top level of a Backbone.js application? A view, generic object,?

I'm confused about what code I should instantiate directly in Backbone.js. Should I create a generic object App that instantiates my views? Should I instantiate an App View that instantiates all the other views on the page and coordinates everything? Should I create views, models and collections and attach them to the window ?

Also, are controllers even necessary? So far I'm not finding any use for them and they are missing from many of the examples out there. Should I instantiate a controller and have it create the other objects as I do in other languages' MVC frameworks?

My guess is I am free to do what I want but I would prefer some advice from somebody who has used it quite a lot.

like image 905
aw crud Avatar asked May 17 '11 11:05

aw crud


People also ask

What are views in Backbone JS?

In backbone. js, there are 7 modules HTTP request, Router, View, Events, Model, and Collection. Whenever a user makes a request it is directed to the router and in response to these requests, a user interface is displayed at the user end which is known as Views.

Which of the following is the correct syntax for creating Backbone view?

js view class to create a custom view. Syntax: Backbone. View.

What is backbone JS give its features?

Backbone. js allows developers to develop one page applications and front-end much easier and better using JavaScript functions. Backbone provides different types of building blocks like models, views, events, routers and collections for assembling client side web applications.

Is Backbone JS frontend or backend?

js. Backbone. js developers usually focus on the front-end aspect of web applications, but also must have basic understanding of some back-end technologies, since their responsibility includes the integration of APIs and resources with front-end elements as provided by the back-end developers and engineers.


1 Answers

Controllers are useful for managing the hashbang URL.

If you don't have multiple pages, states you want to save or want to use the back and forwards buttons then controllers have no use.

Most examples of backbone I've seen have a AppView class that manages views and collections.

See the Annotated Example

like image 157
Raynos Avatar answered Nov 15 '22 00:11

Raynos