I'm creating my very first app with Backbone.
Basically, I have a two-level deep unordered list.

<ul class="cabinet">
      <li class="drawer"> 
        <a>Drawer 1</a>
        <ul class="boxes">
          <li> Box 1 </li>
          <li> Box 2 </li>
      <li class="drawer"> 
        <a>Drawer 2</a>
        <ul class="boxes">
          <li> Box 3 </li>
          <li> Box 4 </li>

In Backbone, I created two collections ("Drawer" and "Boxes"), with their associated Views.
My problem is that I don't know how should I handle the second level list items.

At this moment, I have a single Backbone Collection for boxes and each time I add new Box to
the collection, it will be render under each drawer. I should somehow separate the group of boxes based on the parent drawer but I don't know how can I do this in the "Backbone way".

In other words, let's say I need to add Box 3 and Box 4 elements to Drawer 2.
How can I render this two "boxes" under "Drawer 2". Should I have a separate collection for each drawer's group of boxes? If so, how can I dynamically create a collection with this purpose in Backbone? Is there any other way?

4 Years
Discussion Span
Last Post by McLaren

Congratulations! You're no longer a DaniWeb newbie.<br /> <br />
Your DaniWeb account has just been upgraded from newbie status and now you have the ability to take advantage of everything the community has to offer.<br /> <br />
You can now enjoy an advertisement-free DaniWeb by ticking the checkbox to Disable Ads in your profile. You will no longer have to fill out the human verification check when you post. You can also now send unlimited private messages, contribute new code snippets, and tag articles with never-before-used tags.


Post is so old but it looks like not many lern backbone. I thougth it is very popular. I am also new at backbone but I will try to say what I think:

first thing is - how script would kwow? there are 2 elements with same class - drawer. So first make different ids.

Or are those drawer emelemts also created dynamically?

If let assume drawer elemts are not dynamic, but only boxes are dynamic then maybe seperate view classes for each drawer.

You can set some id to the view class.


Properties like tagName, id, className, el, and events may also be defined as a function, if you want to wait to define them until runtime.

So the view will know on which drawer to put the box.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.