如何将痕迹添加到现有的JSON + LD列表中

时间:2015-03-27 21:50:25

标签: javascript schema breadcrumbs

我有一个JSON + LD对象,我需要动态地向list元素添加项目。如果我从这段代码开始:

var jsonObj = {
    "@context": "http://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement":
    [
        {
            "@type": "ListItem",
            "position": 1,
            "item":
            {
                "@id": "http://domain.com/",
                "name": "Home"
            }
        },
        {
            "@type": "ListItem",
            "position": 2,
            "item":
            {
                "@id": "http://domain.com/used-equipment/",
                "name": "Used Equipment"
            }
        }
    ]
}

如何使用JavaScript在第3位添加其他项目?这甚至可能吗?

1 个答案:

答案 0 :(得分:0)

当然,你就像前两个一样添加它:

[
    {
        "@type": "ListItem",
        "position": 1,
        "item":
        {
            "@id": "http://domain.com/",
            "name": "Home"
        }
    },
    {
        "@type": "ListItem",
        "position": 2,
        "item":
        {
            "@id": "http://domain.com/used-equipment/",
            "name": "Used Equipment"
        }
    },
    {
        "@type": "ListItem",
        "position": 3,
        "item":
        {
            "@id": "Insert URL here",
            "name": "Name of the page"
        }
    }
]