0

In my app, I am keeping a baseCollection, from the baseCollection, i am extending further collections to fetch the data.. But i am getting a error saying:

Uncaught TypeError: Object [object Object] has no method 'extend' 

what would be the reason..?

here is my base collection:

         define(["backbone","models/model"], function (Backbone,model) {

            var baseCollection = Backbone.Collection.extend({
                    //this is the base url
                url:"https://recordsmanager.mahindrasatyam.com/EDMSWSStatic/rest/",
                model:model,
                initialize:function(){
                    console.log("base collection initialized");
                }
            });

            return new baseCollection;

        })

my navigation collection: (extending the base collection):

     define(["backbone","models/model","collection/baseCollection"], function (Backbone,model,baseCollection) {

        var headerCollection = baseCollection.extend({
//i am getting navigation Json my url should be (https://recordsmanager.mahindrasatyam.com/EDMSWSStatic/rest/edms/navigationLinks)
            url:"edms/navigationLinks",
            model:model,
            initialize:function(){

                console.log(baseCollection);
            },
            parse:function(response){

                console.log(response);

            }
        });

        new headerCollection;

    })

But I am not able to extend the base collection. is the way i am doing is wrong..? if so what would be the correct way to extend the base url (I do have no.of views, so i have no.of collection need to extend from base url).

Thanks in advance.

3gwebtrain
  • 14,640
  • 25
  • 121
  • 247

1 Answers1

4

You can't extend an instance but you can extend the collection "class". The thing you want to call extend on is this one:

var baseCollection = Backbone.Collection.extend({ /* ... *? });

not this one:

new baseCollection;

So if your baseCollection is just for extending, then you'd want to:

return baseCollection; // No 'new' here

You'd probably also want to call it BaseCollection as that's the usual and expected capitalization for a collection.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • I changed as like your suggestion, but now the url taking the root as my localhost instead of live url, the error is here: "GET http://localhost/~mohamedarif/edms/edms/navigationLinks 404 (Not Found) " this is my localhost part "http://localhost/~mohamedarif/edms/" – 3gwebtrain Aug 14 '13 at 05:56
  • And that problem should be taken care of over here http://stackoverflow.com/a/18224836/479863 Basically, `extend` doesn't do any merging, it just shadows things that are already there. – mu is too short Aug 14 '13 at 06:41