日期:2014-05-16  浏览次数:20401 次

前台如何分层次显示后台取到的json格式的数据
我后台取得的数据是json格式的,具体如下,还请各位看仔细里面的层次。
{"position":"1","level":"0","is_active":"1","name":"Root","children":[{"position":"3","level":"1","is_active":"1","name":"Root Catalog","children":[{"position":"10","level":"2","is_active":"1","name":"Furniture","children":[{"position":"22","level":"3","is_active":"1","name":"Living Room","children":[],"category_id":"22","parent_id":"10"},{"position":"23","level":"3","is_active":"1","name":"Bedroom","children":[],"category_id":"23","parent_id":"10"}],"category_id":"10","parent_id":"3"},{"position":"13","level":"2","is_active":"1","name":"Electronics","children":[{"position":"8","level":"3","is_active":"1","name":"Cell Phones","children":[],"category_id":"8","parent_id":"13"},{"position":"12","level":"3","is_active":"1","name":"Cameras","children":[{"position":"25","level":"4","is_active":"1","name":"Accessories","children":[],"category_id":"25","parent_id":"12"},{"position":"26","level":"4","is_active":"1","name":"Digital Cameras","children":[],"category_id":"26","parent_id":"12"}],"category_id":"12","parent_id":"13"},{"position":"15","level":"3","is_active":"1","name":"Computers","children":[{"position":"1","level":"4","is_active":"1","name":"Build Your Own","children":[],"category_id":"27","parent_id":"15"},{"position":"2","level":"4","is_active":"1","name":"Laptops","children":[],"category_id":"28","parent_id":"15"},{"position":"3","level":"4","is_active":"1","name":"Hard Drives","children":[],"category_id":"29","parent_id":"13"},{"position":"4","level":"4","is_active":"1","name":"Monitors","children":[],"category_id":"30","parent_id":"13"},{"position":"5","level":"4","is_active":"1","name":"RAM / Memory","children":[],"category_id":"31","parent_id":"13"},{"position":"6","level":"4","is_active":"1","name":"Cases","children":[],"category_id":"32","parent_id":"13"},{"position":"7","level":"4","is_active":"1","name":"Processors","children":[],"category_id":"33","parent_id":"13"},{"position":"8","level":"4","is_active":"1","name":"Peripherals","children":[],"category_id":"34","parent_id":"13"}],"category_id":"15","parent_id":"13"}],"category_id":"13","parent_id":"3"},{"position":"18","level":"2","is_active":"1","name":"Apparel","children":[{"position":"4","level":"3","is_active":"1","name":"Shirts","children":[],"category_id":"4","parent_id":"18"},{"position":"5","level":"3","is_active":"1","name":"Shoes","children":[{"position":"16","level":"4","is_active":"1","name":"Mens","children":[],"category_id":"16","parent_id":"5"},{"position":"17","level":"4","is_active":"1","name":"Womens","children":[],"category_id":"17","parent_id":"5"}],"category_id":"5","parent_id":"18"},{"position":"19","level":"3","is_active":"1","name":"Hoodies","children":[],"category_id":"19","parent_id":"18"},{"position":"24","level":"3","is_active":"0","name":"Pants","children":[],"category_id":"24","parent_id":"18"}],"category_id":"18","parent_id":"3"},{"position":"20","level":"2","is_active":"0","name":"Household Items","children":[],"category_id":"20","parent_id":"3"}],"category_id":"3","parent_id":"1"}],"category_id":"1","parent_id":"0"};