1

如何创建一个里面有 RABL 集合的孩子?

JSON 需要:集合 @listings 应该是结果的子项。

{
    result: {
        listings: [
            {
                id: 1,

            },
            {
                id: 2,

            }
        ]
    }
}

带有子集的 RABL 模板:

object false

child @result => :result do
  collection @rents , :root => "listings", :object_root => false  

  attributes :id

end

但我得到与上述模板一样的输出:

{
    result: [
        {
            id: 1
        },
        {
            id: 2
        }
    ]
}
4

1 回答 1

1

我从来没有使用过RABL,但是你不能做这样的事情吗?:

object false

child @result => :result do
  child :listings
    collection @rents , :root => "listings", :object_root => false  
  end
  attributes :id

end
于 2013-07-05T13:43:28.050 回答