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數組?
以在[註釋的源代碼]快速查看(http://documentcloud.github.com/backbone/docs/backbone.html)以下的jsfiddle,它看起來像你可能會嘗試Platforms.toJSON() – 2012-03-05 16:01:28