以Accordion视图格式

时间:2018-02-23 07:30:20

标签: html ruby-on-rails json

在我的rails应用程序中,JSON文件是通过控制器动态生成的。现在我用render :json => JSON.pretty_generate(@xml_hash), :status => :ok渲染它,它就像树状结构

{
  "hotel_inventory": {
    "xmlns": "http://www.example.com/abc",
    "type": "update",
    "hotel_id": "12",
    "room_type_id": "13",
    "room_inventories": {
      "room_inventory": [
        {
          "from_date": "15/02/2018",
          "to_date": "18/02/2018",
          "applicable_days": "ALL",
          "inventory": "5",
          "release_hours": "0"
        },
        {
          "from_date": "19/02/2018",
          "to_date": "19/02/2018",
          "applicable_days": "ALL",
          "inventory": "4",
          "release_hours": "0"
        },
        {
          "from_date": "01/03/2018",
          "to_date": "31/03/2018",
          "applicable_days": "ALL",
          "inventory": "5",
          "release_hours": "0"
        }
      ]
    }
  }
}

我希望它采用可折叠的格式(手风琴视图)我尝试过很多东西但没有取得任何成功。

1 个答案:

答案 0 :(得分:0)

您可以使用浏览器插件 Json-Formatter像这样在浏览器中显示你的json-response。