我有文件和文件夹。文件夹包含文件。
我从服务器获取的 JSON 如下所示:
folder: {id: 5, name: "my stuff" }
file: {id: 3, name: "my file", folderId: 5}
file: {id: 5, name: "my file 2", folderId: 5}
构建文件夹 - 文件结构的最佳方法是什么?将文件嵌套在文件夹中,例如:
{id: 5, name: "my stuff" files: [
{id: 3, name: "my file", folderId: 5},
{id: 5, name: "my file 2", folderId: 5}
]},
{id: 6, name: "other things" files: [
{id: 1, name: "my file", folderId: 6},
{id: 2, name: "my file 2", folderId: 6}
]}
或者使用仅返回属于文件夹 id 的文件的过滤器?喜欢:
<li ng-repeat="folder in folders">
<ul>
<li ng-repeat="file in files | fileInFolder:folder.id"></li>
</ul>
</li>
文件可以移动到不同的文件夹!