2012-03-05 80 views
5

我有一个骨干集合Platforms。的Platforms的结构是这样的:Backbone.js:从集合中生成JSON数组

Platforms 
    PlatformList 
    models 
     0: Platform 
     attributes 
      id: 1 
      name: "some name" 
     1: Platform 
     attributes 
      id: 2 
      name: "some other name" 

我需要提取从集合中的模型的属性,并建立在以下格式的JSON数组:

[{"id":1,"name":"some name"},{"id":2,"name":"some other name"}] 

调用Platforms.models.toJSON()JSON.stringify(Platforms.models)结果在一个文字字符串"[[object Object], [object Object]]"

我怎样才能建立我需要从这个集合的JSON数组?

+1

以在[注释的源代码]快速查看(http://documentcloud.github.com/backbone/docs/backbone.html)以下的jsfiddle,它看起来像你可能会尝试Platforms.toJSON() – 2012-03-05 16:01:28

回答