Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backbone.js - views within views and managing events

What's a good way to organize views? Let's say I have a div that will contain a view from an admin panel perspective of users - there will be a list of users along with options to choose how many to display at a time, sorting options, what page to be on, filters, etc...

Would I want an outside view that contained everything except the table and data? And then an inside view that contains the table (along with the data)? And would the pagination have it's own view? And how would the pagination view use the click event to update the user view? I'm just confused on how to organize the views while still being able to have different events trigger other views to render() / collections to fetch().

So a basic hierarchy would look like:

- User View
  - Table
    - List of Users
  - Pagination
    - List of available numbers to click
  - Filters
    - Possible filters to apply to the data

Yet clicking a filter or number in the pagination should be able to get the collection to fetch() new data and refresh the view;

like image 260
Matthew Avatar asked Apr 17 '11 15:04

Matthew


People also ask

Do people still use Backbone JS?

Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.

What are views in Backbone JS?

The Backbone. js Views specify how your data looks like. They represent model's data to the users. They can be used with any JavaScript template library.

What is the only method available in the backbone JS history?

There is only method named "start" can be used to manipulate the Backbone. js history.

What is backbone JS comparable to?

Vue. js, React, AngularJS, Angular 2, and Ember. js are the most popular alternatives and competitors to Backbone. js.

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.


1 Answers

I second dogenpunk. I would have one User Collection / View. Because the whole hierarchy you describe above is about that one User Collection. All functions of it manipulate that collection and then you rerender the User View.

You could have a second User View, one single User, tied to a Model if you want to apply changes to the server for that user only.

like image 198
thgie Avatar answered Oct 17 '22 10:10

thgie