Question

When I am trying to call the collections.fetch method i am getting the following error in console :

Uncaught TypeError: Object function (a){return new j(a)} has no method 'isObject' 

Here is my app.js :

 var Items = Backbone.Collection.extend({
    url : function() {
        return "names/all/" + this.pageStart + "-" + this.pageEnd;
    },
    pageStart : 1,
    pageEnd : 5
});

var ScrollView = Backbone.View.extend({
    el : $('#list'),
    initialize : function() {
        _.bindAll(this, 'getNames');
        this.collection.bind('all', this.addAll);
        this.collection.fetch(); //getting error coz of this line here.
    },
    getNames : function() {
        this.collection.fetch();
    },

    addAll : function() {
        alert(JSON.stringify(this.collection));
        this.collection.each(function(item) {
            alert(":");
            this.addOne(item);
        });
    },
    addOne : function(item) {
        alert(item);
    }
});
var coll = new Items();
var scrollView = new ScrollView({collection: coll});

Here is the scripts versions i am using

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>

However the response i am getting from the server is OK 200 status This is the respose i am getting

[{"firstName":"A","lastName":"last","id":"1"},{"firstName":"B","lastName":"last","id":"2"},{"firstName":"C","lastName":"last","id":"3"},{"firstName":"D","lastName":"last","id":"4"},{"firstName":"E","lastName":"last","id":"5"}]

And finally these are my response headers:

Request URL:http://localhost:8080/mongodb/names/all/1-5
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:8080
Referer:http://localhost:8080/mongodb/
User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5
X-Requested-With:XMLHttpRequest
Response Headersview source
Content-Type:application/json;charset=UTF-8
Date:Thu, 31 May 2012 17:32:10 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked

Please help someone. Thanks in advance.

Was it helpful?

Solution

You use underscore 1.1.6 with backbone 0.9.2 which requires underscore 1.3.1.

See http://backbonejs.org/#upgrading

Upgrading to 0.9

If you're upgrading, make sure you also upgrade your version of Underscore.js to the latest — 1.3.1 or greater.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top