javascript - Accessing parent node in a JSON object - Stack Overflow

Having problems calling my parent Title ("Main title") in my JSON object. Below is a fiddle w

Having problems calling my parent Title ("Main title") in my JSON object. Below is a fiddle with what I currently have. (I can get it to call all child nodes in items, but again need to figure out how to call "title: Main Title")

/

Current JSON Tree

{
    "title": "Main Title",
    "items": [{
        "title": "Sub Title 1 "
    },
    {
        "title": "Sub Title 2",
        "items": [{
            "title": "Sub Item 1"
        },
        {
            "title": "Sub Item 2"
        }]
    },
    {
        "title": "Sub Title 3",
        "items": [{
            "title": "Sub Item 1"
        },
        {
            "title": "Sub Item 2"
        }]
    },
    {
        "title": "Sub Title 4 "
    }]
}

Having problems calling my parent Title ("Main title") in my JSON object. Below is a fiddle with what I currently have. (I can get it to call all child nodes in items, but again need to figure out how to call "title: Main Title")

http://jsfiddle/VVAFM/3/

Current JSON Tree

{
    "title": "Main Title",
    "items": [{
        "title": "Sub Title 1 "
    },
    {
        "title": "Sub Title 2",
        "items": [{
            "title": "Sub Item 1"
        },
        {
            "title": "Sub Item 2"
        }]
    },
    {
        "title": "Sub Title 3",
        "items": [{
            "title": "Sub Item 1"
        },
        {
            "title": "Sub Item 2"
        }]
    },
    {
        "title": "Sub Title 4 "
    }]
}
Share Improve this question edited Oct 17, 2011 at 1:31 user113716 323k64 gold badges453 silver badges441 bronze badges asked Oct 17, 2011 at 1:20 StarboyStarboy 1,6353 gold badges20 silver badges27 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

you can try the new JSON SELECT engine, looks interesting and affords CSS-like select statements over your JSON.

http://jsonselect/#overview

having said that, you can reference it differently like so: http://jsfiddle/dimitar/VVAFM/4/

the title var will refer to main title, always.

good luck :)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745358281a4624242.html

相关推荐

  • javascript - Accessing parent node in a JSON object - Stack Overflow

    Having problems calling my parent Title ("Main title") in my JSON object. Below is a fiddle w

    9小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信