我有一些jsons数据如下所示,当我尝试使用ng-include和ng-template递归打印它们时(如下所示),ng-include的内部html代码不会呈现,而且它是空白的。 和其他问题是,在打印ng-include时,它只打印1级递归,而且不会继续打印。
那怎么了?
Json数据:
[{"name":"default","path":">var>www>rapa-v2>themes>","subdir":[{"name":"css","path":">var>www>rapa-v2>themes>>default","subdir":[{"name":"images","path":">var>www>rapa-v2>themes>>default>css","subdir":[]},{"name":"style.css","path":">var>www>rapa-v2>themes>>default>css"}]},{"name":"index.blade.php","path":">var>www>rapa-v2>themes>>default"},{"name":"information.json","path":">var>www>rapa-v2>themes>>default"},{"name":"screen.jpg","path":">var>www>rapa-v2>themes>>default"}]}]
Html代码:
<div class="theme-files-list ltr" ng-init="loadDir('{{ $theme }}')">
<script type="text/ng-template" id="directoryTree">
<div class="tree-item">
<i class="fa fa-file-text-o maroon"></i>
<a href="<% '/admin/setting/template/edit/{{ $theme }}/'+item.name %>">
<% item.name %>
</a>
</div>
<ul ng-if="item.subdir">
<li ng-repeat="item in item.subdir" ng-include="'directoryTree'"></li>
</ul>
</script>
<ul class="noselect">
<li>
<div class="tree-item bg-aqua">
<i class="fa fa-paint-brush blue"></i>
{{ ucfirst($theme) }}
</div>
<ul>
<li ng-repeat="item in themeDir" ng-include="'directoryTree'"></li>
</ul>
</li>
</ul>
</div>
重要:我使用laravel并进行刀片系统打印,我已用&lt; %%&gt;
替换角度打印符号{{}}
答案 0 :(得分:0)
我认为你必须使用不同的代码。你的json代表一个文件夹树,但是在角度应用程序中,你只是在第一级迭代,而在第一级你只有1个子目录。
如果您正确格式化了json响应,您可以轻松理解这一点。
[
{
"name":"default",
"path":">var>www>rapa-v2>themes>",
"subdir":
[
{
******** You're targeting this element below **********
"name":"css",
"path":">var>www>rapa-v2>themes>>default",
"subdir":
[
{
"name":"images",
"path":">var>www>rapa-v2>themes>>default>css",
"subdir":[]
},
{
"name":"style.css",
"path":">var>www>rapa-v2>themes>>default>css"
}
]
},
{
******** This doesn't has subdir **********
"name":"index.blade.php",
"path":">var>www>rapa-v2>themes>>default"
},
{
******** This doesn't has subdir **********
"name":"information.json",
"path":">var>www>rapa-v2>themes>>default"
},
{
******** This doesn't has subdir **********
"name":"screen.jpg",
"path":">var>www>rapa-v2>themes>>default"
}
]
}
]
所以你必须改变json或改变ng-repeat