我有一些路径:
CCCCC,D D D D,aaaaa,bbbbb,test 2.txt,test1.txt,CCCCC/a,CCCCC/a/test 2.txt,CCCCC/a/test1.txt,D D D D/aaaa.fr,D D D D/test 2.txt,D D D D/test1.txt,D D D D/aaaa.fr/test 2.txt,D D D D/aaaa.fr/test1.txt,aaaaa/test 2.txt,aaaaa/test1.txt,bbbbb/aaaaaaaaaaa.txt,bbbbb/fffffffff,bbbbb/fffffffff/test 2.txt,bbbbb/fffffffff/test1.txt
我递归地创建树( file.id 和 file.children )并用 JADE 显示...
我尝试编写正确的路径但不起作用。
Jade(以空字符串开头的路径:
mixin file_list(files, path)
ul
each file, i in files
li
- if(file.children.length > 0){
span #{file.id}
- path += file.id + '\\';
mixin file_list(file.children, path)
- }else{
span
a(href='#{path}#{file.id}') #{file.id}
- }
展示:
<ul>
<li><span>CCCCC</span>
<ul>
<li><span>a</span>
<ul>
<li><span><a href="CCCCC\a\test 2.txt">test 2.txt</a></span></li>
<li><span><a href="CCCCC\a\test1.txt">test1.txt</a></span></li>
</ul>
</li>
</ul>
</li>
<li><span>D D D D</span>
<ul>
<li><span><a href="CCCCC\D D D D\test 2.txt">test 2.txt</a></span></li>
<li><span><a href="CCCCC\D D D D\test1.txt">test1.txt</a></span></li>
<li><span>aaaa.fr</span>
<ul>
<li><span><a href="CCCCC\D D D D\aaaa.fr\test 2.txt">test 2.txt</a></span></li>
<li><span><a href="CCCCC\D D D D\aaaa.fr\test1.txt">test1.txt</a></span></li>
</ul>
</li>
</ul>
</li>
<li><span>aaaaa</span>
<ul>
<li><span><a href="CCCCC\D D D D\aaaaa\test 2.txt">test 2.txt</a></span></li>
<li><span><a href="CCCCC\D D D D\aaaaa\test1.txt">test1.txt</a></span></li>
</ul>
</li>
<li><span>bbbbb</span>
<ul>
<li><span><a href="CCCCC\D D D D\aaaaa\bbbbb\aaaaaaaaaaa.txt">aaaaaaaaaaa.txt</a></span></li>
<li><span>fffffffff</span>
<ul>
<li><span><a href="CCCCC\D D D D\aaaaa\bbbbb\fffffffff\test 2.txt">test 2.txt</a></span>
</li>
<li><span><a href="CCCCC\D D D D\aaaaa\bbbbb\fffffffff\test1.txt">test1.txt</a></span></li>
</ul>
</li>
</ul>
</li>
</ul>
为什么变量路径不重置?