1

I'm building a media player menu with Backbone.JS that have different smaller options for each option, i.e. shuffle can have specific intervals/entire song/etc., repeat for repeat 1 song or repeat playlist, next, previous.

Right now, I have a Backbone model called Menu, which lists all these options within it. After reading up some more, I realize I should have separate models for each of these options. But after reading the post linked below, I am a bit confused. The Menu options I have should not be a collection, right? So I'm a bit confused between these options and how to template each one:

1) Keep all my options in a Menu model, and update subViews accordingly 2) Have a separate model for each option, and update a corresponding view 3) Have a collection of all these models, so

Related: loops in underscore js template

Community
  • 1
  • 1
gotta have my pops
  • 878
  • 4
  • 11
  • 22

2 Answers2

0

Most likely the menu itself should be a collection and each item should be a model.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
0

I don't think you necessarily need to have several models for each menu option; it's entirely up to how you want to structure your code. You really could do any of the following:

  1. one view, no model at all (just hard-coded menu options)
  2. one view, one model
  3. one view, separate models for each menu option
  4. one view per menu option, all
  5. one view per menu option, each with their own modelsharing a single model

Any of the above could be the best answer to your particular situation, but without knowing more details (eg. what data makes up a single menu option, does this data come together or as the result of multiple AJAX calls, etc.) it's hard to advocate for one over the other.

Personally I would just start with the simplest option (#1), and switch to #2 as soon as it gets awkward. Then if #2 got awkward I'd switch to #3 or #4, and so on. Basically, choose the simplest path that doesn't make you wish you'd picked a more complicated path ;-)

Oh, and if you do wind up going with a multiple model approach, putting all those models in a collection would definitely make sense.

machineghost
  • 33,529
  • 30
  • 159
  • 234