maximus
maximus

Reputation: 4302

Backbone: fetch information to model by demand

I want to make a Model-View behaviour in backbone.js, so that not all information will be loaded at the begining. For example I have a player infromation in the Player Model:

var Player = Backbone.Model.extend({
    initialize: function() {
        },
    defaults: {
        name: "",
        surname: "",
        someOtherInfo: ...
    }
});

I want to show the players list in a table, where only player name and surname will be shown, however, if user clicks a player, more detailed information will be shown, by fetching other attributes (someOtherInfo).

Is there a way to do it when calling fetch?

Upvotes: 1

Views: 180

Answers (1)

Tommi Komulainen
Tommi Komulainen

Reputation: 2880

Your API methods returning the list/collection can return different data than the API method for fetching a specific model. Just populate the collection with only the data needed for the list and when an item is selected fetch that specific model to fill in the blanks.

Upvotes: 4

Related Questions