【问题标题】:Uncaught TypeError: Converting circular structure to JSON : Backbone未捕获的类型错误:将循环结构转换为 JSON:主干
【发布时间】:2013-06-27 01:23:52
【问题描述】:

我正在尝试保存一个骨干集合,如下所示:

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,它也阻止了服务器调用。

编辑

从服务器获取()后,我的数据将类似于以下 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"
    }
]

它也被填充到表格中。

【问题讨论】:

  • hi mu太短了,希望你也可以关注http://stackoverflow.com/questions/17378924/region-is-acting-strange-when-the-page-is-refreshed请
  • 请看一下我的编辑。
  • 我也遇到了同样的错误,但在我的情况下,当我得到 string("") 而不是 json={} 对象时会发生这种情况。

标签: json backbone.js marionette backgrid


【解决方案1】:

我在将模型添加到集合时出错了,我添加了一个类型而不是该类型的实例。

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

是我应该添加的类型

var row = new backgridModel() 我使用backgridModel 创建了一个新行。

【讨论】:

    猜你喜欢
    • 2017-03-22
    • 2012-05-17
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-12
    • 2019-01-31
    • 2021-07-23
    相关资源
    最近更新 更多