...images
......|vertical
......|horizontal
...Jquery
......|UI
......|include
...quickfox
要处理的数组: 我有类似上面的文件夹结构。它存储在数组目录中。见下文
var dirs = [
"images",
"images/vertical",
"images/horizontal",
"Jquery",
"Jquery/UI",
"Jquery/include",
"quickfox"
];
目标:如何制作嵌套的 ul li,如下所示。
<ul id="categorymenu">
<li>images </li>
<ul>
<li>vertical</li>
<li>horizontal</li>
</ul>
<li>Jquery</li>
<ul>
<li>UI</li>
<li>include</li>
</ul>
<li>quickfox</li>
</ul>
更新:XML 结构
<directory name="images">
<file path="BBB.gif" width="500" height="282">BBB.gif</file>
<file path="AAA.jpg" width="964" height="525">AAA.jpg</file>
<directory name="images/vertical">
<file path="CCC.jpg" width="964" height="525">CCC.jpg</file>
</directory>
<directory name="images/horizontal">
<file path="DDD.jpg" width="964" height="525">DDD.jpg</file>
</directory>
</directory>
这是我从 xml 制作数组的地方。
$(document).ready(function () {
//------ READ XML -----------
$.ajax({
type: "GET",
url: "___deck.xml",
dataType: "xml",
success: function (data) {
my_xml = data;
xmlDirParser(my_xml);
}
});
//------ Get Files on List Change -----------
$("#dirlist").change(function () {
var folder = $(this).find('option:selected').text();
xmlFileParser(folder, my_xml);
});
});
function xmlDirParser(my_xml) {
$(my_xml).find('directory').each(function () {
var dirname = $(this).attr('name');
// $('#dirlist').append('<option value="1">'+dirname+'</option>');
//This is where I get dirs array
});
}