3

次のようなバックボーン コレクションを保存しようとしています。

var backgridModel = Backbone.Model.extend({ });

var BackgridCollection = Backbone.Collection.extend({
    model: backgridModel,
    url : 'api/list'
});

var backgriCollections = new BackgridCollection();
backgriCollections.fetch();

var CreatePuppetRequest = Backbone.Model.extend({
    url : 'api/createTable',
    toJSON: function() {
        console.log(backgriCollections.toJSON());
        return backgriCollections.toJSON();
    }
});

次のようにサーバー呼び出しを行います。

var puppetTable = new CreatePuppetRequest();
puppetTable.save({}, {
    success : function(model, response) {
        alert("Successfully submitted " + num + " puppet(s)");
        puppetFinalCollection.reset();
        $('#create-puppet-table-button').removeAttr("disabled");
    },
    error : function(model, response) {
        if (response.status == 400)
            that.showErrors($.parseJSON(response["responseText"]));
        else
            console.log(response["responseText"]);
        puppetFinalCollection.reset();
        $('#create-puppet-table-button').removeAttr("disabled");
    }
});

コンソール出力

0: Object
designation: "m"
firstName: "sdfghj"
function (){ return parent.apply(this, arguments); }: Object
lastName: "sdfghj"
__proto__: Object
length: 1
__proto__: Array[0]

function (){ return parent.apply(this, arguments); }: Objectなぜ追加されたのかわからないモデルに余分に追加されますか?

Uncaught TypeError: Converting circular structure to JSONこれに加えて、サーバー呼び出しもブロックするこれを取得します。

編集

サーバーからの fetch() の後、データは次の JSON 文字列のようになります。

[
    {
        "userid": "",
        "firstName": "Mayank",
        "lastName": "Kumar",
        "designation": "Software Engineer"
    },
    {
        "userid": "",
        "firstName": "Shylendra",
        "lastName": "Bhat",
        "designation": "Software Engineer"
    },
    {
        "userid": "",
        "firstName": "Akash",
        "lastName": "Waran",
        "designation": "Software Engineer"
    },
    {
        "userid": "",
        "firstName": "Shreyas",
        "lastName": "Lokkur",
        "designation": "Software Engineer"
    },
    {
        "userid": "",
        "firstName": "Anthony",
        "lastName": "Raj",
        "designation": "Software Engineer"
    },
    {
        "userid": "",
        "firstName": "Dheemanth",
        "lastName": "Bharadwaj",
        "designation": "Software Engineer"
    },
    {
        "userid": "",
        "firstName": "Prasanna",
        "lastName": "Adiga",
        "designation": "Software Engineer"
    }
]

そしてそれはテーブルにも取り込まれています。

4

1 に答える 1

-1

モデルをコレクションに追加するときに間違いを犯しました。タイプのインスタンスではなくタイプを追加しました。

var backgridModel = Backbone.Model.extend({ });

私が追加すべきだったタイプです

var row = new backgridModel()代わりにbackgridModel、新しい行を作成するために使用しました。

于 2013-07-01T10:13:47.547 に答える