So, first of all, why am I doing this? I’m developing a simple webapp to sell cars. It’s the simplest projects among all that I’m involved now, but it has some interesting things. I hope, when the project is released, I’ll be open-sourcing some of its components.
One of the things I had to do was to reuse some lists but with a different item layout. For example, when displaying cars to all the viewers, they’ll have some data, and when it’s displayed to the admin, it must contains some buttons to edit, delete or send emails for the clients.
What’s the difference between the two lists? Both will use tables to display the data, but one of them will have a different layout and will display a header… the other no. Furthermore, the non-admin view will show a filter view, which is not working now.
Now, it’s time to see some code. To declare all the Backbone.js variables I will use the following structure in the file cars.js:
Now that you know which structure we’ll use, we’ll define the two item views. First, let’s define the regular item view: