我想弄清楚这一点,我正在尝试构建一个具有多级的简单菜单树
RootFolder
- First Sub Folder
-- First Sub Sub Folder
--- First Sub Sub Sub Folder
--- First Sub Sub Sub Sub Folder
- Second Sub Folder
- Second Sub Sub Folder
我的 XML 非常简单(不是正确的值)
<OrgFolderDetails>
<FolderName>Main Folder</FolderName>
<TheChildren>
<OrgFolderDetails>
<FolderName>First Sub Folder</FolderName>
<TheChildren>
<OrgFolderDetails>
<FolderName>First Sub Sub Folder</FolderName>
<TheChildren>
<OrgFolderDetails>
<FolderName>First Sub Siub Sub Folder</FolderName>
<TheChildren>
<OrgFolderDetails>
<FolderName>First Sub Sub Sub Sub Folder</FolderName>
<TheChildren/>
</OrgFolderDetails>
</TheChildren>
</OrgFolderDetails>
</TheChildren>
</OrgFolderDetails>
</TheChildren>
</OrgFolderDetails>
<OrgFolderDetails>
<FolderName>Second Sub Folder</FolderName>
<TheChildren>
<OrgFolderDetails>
<FolderName>Second Sub Sub Folder</FolderName>
<TheChildren/>
</OrgFolderDetails>
</TheChildren>
</OrgFolderDetails>
</TheChildren>
</OrgFolderDetails>
我使用了 jQuery 的 .filter() 和。find() each() 没有任何成功,它没有给我漂亮的破折号来指示我在哪个级别,它只是吐出文件夹名称。
我的代码遍历
$(data).find("FolderName").each(function(){
var folderName = $(this).text();
$("#folderLevels").append(folderName+"<br/>");
});