3gwebtrain
3gwebtrain

Reputation: 15293

Backbone.js - How to make sub models within Main models?

In my app, i have main naivgation link with sublinks (drop down menus) - i am calling my collection from navigation view, and i am getting the json response like this:

[{"label": "General","link":"#/general",
  "subLinks": [{"label": "Dashboard",     "link": "#/dashboard"},
               {"label": "My Task",       "link": "#/mytask"},
               {"label": "My Documents",  "link": "#/mydocuments"},
               {"label": "My Templates",  "link": "#/mytemplates"},
               {"label": "Repositories",  "link": "#/reposotories",  "subLinks": []},
               {"label": "SavedSearches", "link": "#/savedSearches", "subLinks": []}
]

my question is how to convert this in to backbone models.. especially how can i handle the sublinks relation of each main links..? (how to make nested models in main model)

Upvotes: 0

Views: 122

Answers (1)

namero999
namero999

Reputation: 3002

You have to use parse.

With parse, you are in control of translating the raw response to your model object. There, for instance, you could take the raw subLinks array and feed it to a Collection of yours, and then set the popoluated collection as a property of your Model.

Upvotes: 1

Related Questions