0

Is it possible to pass url parameter when creating an instance of Collection object? I would like to create an array of collections containing data for all pages.

var Collection = Backbone.Collection.extend({ 
    model: MainModel,
    initialize: function (models,options) {
        var self = this;
        self.fetch();   
    }
});

var Collections = {
    news : new Collection({url : "../data/news"}),
    projects : new Collection({url : "../data/projects"}),
    home : new Collection({url : "../data/home"})
};

Is that possible like this, or I am doing something terribly wrong? Do I need to create a collection for each page?

hjuster
  • 3,985
  • 9
  • 34
  • 51

2 Answers2

1

Generally you will want to create a new collection for each type of model

yujingz
  • 2,271
  • 1
  • 25
  • 29
  • I guess I know what you mean. You have a page, contains lot of informations like news, projects, etc. You want to manage them as a whole, in a collection array. So if you want to like go to next page, you can just go through the array of collections and fetch – yujingz Apr 05 '13 at 18:25
0

I also find this issue and i get it solved .. Here is the quick answer.

Collection Object

 var Events = Backbone.Collection.extend({
        initialize : function(models,options){
            this.model = options.model ,
            this.url = options.url
        }
    });

here is how i create my new collection instace

var events = new Events([],{ model : modelName , url : 'urlToGo' });

Hope you help

Sanny Singhs
  • 73
  • 1
  • 2
  • 10