当我尝试调用 collections.fetch 方法时,我在控制台中收到以下错误:
Uncaught TypeError: Object function (a){return new j(a)} has no method 'isObject'
这是我的 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});
这是我正在使用的脚本版本
<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>
但是我从服务器得到的响应是 OK 200 status 这是我得到的响应
[{"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"}]
最后这些是我的响应标头:
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
请帮助某人。提前致谢。