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>
        </ul>
      </li>
      <li class="drawer"> 
        <a>Drawer 2</a>
        <ul class="boxes">
          <li> Box 3 </li>
          <li> Box 4 </li>
        </ul>
     </li>
    </ul>

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?

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.

http://backbonejs.org/#View

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.