0

从 API 获取 Backbone.js 集合时,Backbone 需要一个 JSON 数组:

[
    {
        id: 1,
        name: "whatever"
    },
    {
        id: 2,
        name: "another"
    }
]

我想这是一个安全风险,请参阅:JSON security best practice?

我想让 Backbone 理解以下格式:

{
    things: [
        {
            id: 1,
            name: "whatever"
        },
        {
            id: 2,
            name: "another"
        }
    ]
}

我有一个简单的方法来做到这一点?

4

1 回答 1

0
var Library = Backbone.Collection.extend({
  parse: function(response) { // This is called after the `fetch()` got its data
    return response.things;
  }
});

但是我没有看到任何使用简单数组的安全威胁..

于 2013-07-03T18:38:16.773 回答