1

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ステータスこれは私が取得している応答です

[{"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

誰かを助けてください。前もって感謝します。

4

1 に答える 1

4

アンダースコア1.3.1を必要とするバックボーン0.9.2でアンダースコア1.1.6を使用します。

http://backbonejs.org/#upgradingを参照してください

0.9へのアップグレード

アップグレードする場合は、Underscore.jsのバージョンも最新の1.3.1以降にアップグレードしてください。

于 2012-05-31T18:01:13.200 に答える