最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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 :)

发布评论

评论列表(0)

  1. 暂无评论