我目前正在構建一個基於jQuery的遞歸菜單,該菜單已經很好看了。使用jQuery在Json文件中查找所有父母元素
包含菜單JSON文件的結構看起來如下:
[
{
"Id": "menuOfficeWebControlsForWebApplication",
"Title": "Office Web Controls",
"Resource": "/Documentation/Data/index.html" },
{
"Id": "menuGettingStarted",
"Title": "Getting Started",
"Resource": "/Documentation/Data/getting-started.html",
"Categories": [{
"Id": "menuCompilingFromSource",
"Title": "Compiling From Source",
"Resource": "/Documentation/Data/Getting-Started/compiling-from-source.html"
},{
"Id": "menuDownloadReleasePackage",
"Title": "Download Release Package",
"Resource": "/Documentation/Data/Getting-Started/downloading-release-package.html"
},{
"Id": "menuBuildingYourFirstApplication",
"Title": "Building your first application",
"Resource": "/Documentation/Data/Getting-Started/building-your-first-application.html"
}]
}
]
現在,我可以出使用jQuery和結果菜單的檢索項目可能是這個項目:
{
"Id": "menuBuildingYourFirstApplication",
"Title": "Building your first application",
"Resource": "/Documentation/Data/Getting-Started/building-your-first-application.html"
}
現在,我想檢索所有更高級別的元素以及該項目正下方的所有項目。
任何幫助,高度讚賞。
什麼是父母?任何不是當前節點的節點?你是否可以改變節點(例如添加一個ParentNode屬性) –
我可以那樣做,但是很容易出現輸入錯誤。父母是層級中較高的元素。 – Complexity