简体   繁体   中英

How can I render complex json in rails?

I have object nav in my rails application. But the nav obj will have another nav obj.

My question is, how can i output or render json like this that nav have another sub nav and may have unlimited depth? Many thanks!!!

"nav": [
            {
                "id": 1,
                "name": "Home",
                "icon": "home",
                "nav": [{  id: 2,
                           name: "game"
                           icon: 'game'
                           etc.......

  }],

使用JbuilderRabl等工具。

jbuider is the solution for complex json.

Check the great tutorials for complex json (jbuider) -

1) jbuider Asciicast

2) jbuider customized Json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM