/cities//suburbs returns a list of all suburbs within a city that has a particular. /countries//cities returns a list of all the cities within a country that has a particular./countries returns a list of all countries, each of which comprises an id and a name.Furthermore, we’ll also assume that all of this data can be accessed as JSON via RESTful URLs in the Rails style. Under the hood we’ve got a hierarchy of data structures, where a Country has many Cities, and a City has many Suburbs. Sure, it’s not going to win any beauty contests, but that’s not why we’re here, is it? In this example, our hierarchy of select boxes will represent locations: specifically, countries, cities within those countries, and suburbs within those cities. It’s also an example that is surprisingly difficult to do correctly. Consequently, it’s an example where – one way or another – views have to interact with one another. When you select an item in one select box, the list of options in the next select box down the hierarchy is repopulated. This is where we have a series of HTML select elements that represent data in a hierarchy. We’ll use an example that’s a little bigger than just a single view and model: the classic “cascading select” user interface. Note that this isn’t an introduction to Backbone.js, and assumes a little background knowledge of how the framework works. You’ll see that Backbone.js provides a good basis for building apps in an MVC style, although you will be faced with the same design decisions you’d have to make with any other MVC framework. Furthermore, I’ll present it in a manner that is iterative, rather than just dropping the whole thing on you in one hit. In this entry I’ll try to present an example that is slightly bigger than your average single model and view. I have recently had the opportunity to work on a non-trivial Backbone.js application. What should be in a model and what should be in a view? How should models and views interact with each other? Simple tutorials abound that describe how to hook up a single view to a single model, but it’s unclear what approach to use for more complex UIs. The API documentation is complete, yet joining the dots can be a little intimidating at times to a newby. For an expert, that might be a good thing. It’s lightweight, works with jQuery (although it doesn’t need it) and seems to have some momentum behind it at the moment.īackbone.js isn’t particularly large or opinionated in the manner of say, Rails. Fortunately, there’s been a recent proliferation of Javascript MVC frameworks, both large and small. Libraries like jQuery have certainly helped, but with the rise of Single-Page Applications, jQuery alone doesn’t provide enough of an overall framework for large-scale client-side development. What happens when you don’t use BackboneUp until recent years, client-side Javascript development has resembled the wild-west from a software design perspective.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |