6
我有這個Rabl的模板JSON對象,而根密鑰Rabl的:</p> <pre><code>object @photo attributes :id child :comments do attributes :id, :body end </code></pre> <p>這給了我這個JSON響應:
{
photo: {
id: 1,
comments: [
{
comment: {
id: 1,
body: 'some comment'
}
},
{
comment: {
id: 2,
body: 'another comment'
}
}
]
}
}
但我希望它看起來像這樣:
{
id: 1,
comments: [
{
id: 1,
body: 'some comment'
},
{
id: 2,
body: 'another comment'
}
]
}
爲什麼rabl會用一個名爲comment
的額外對象來包裹陣列中的每個元素。這樣,當我訪問集合中的JavaScript我有寫:的
var comment = image.comments[0].comment
代替:
var comment = image.comments[0]
我知道,如果我包括在屬性列表中@photo
對象:comments
它的工作原理我想要的方式,但是當我想要每個comment
對象的另一級嵌套關聯時,除了使用child
之外,沒有辦法處理它,但是這給了我不想要的JSON響應。
也許我只是誤解了整個事情 - 有人可以解釋或幫助嗎?謝謝!
我有同樣的問題,我發現我需要添加「config.include_child_root =假」除了include_json_root = FALSE – 2012-10-21 19:04:59