我在 AngularJS 中有一个原型解决方案,它使用以下数据结构:
$scope.clients = [
{ client:"Client1", projects:[
{ project: "Project1", items:[
{ item: "This is the first item" },
{ item: "This is the second item" }
]},
{ project: "Project2", items:[
{ item: "This is the third item" },
{ item: "This is the fourth item" }
]}
]},
{ client:"Client2", projects:[
{ project: "Project4", items:[
{ item: "This is the fifth item" },
{ item: "This is the sixth item" }
]}
]}
];
我正在寻找实现后端,但我不确定 API 是否应该为客户端提供上述嵌套数据结构,或者是否应该为项目提供平面结构,然后 AngularJS 客户端应用程序创建嵌套结构。以下是 API 将提供的平面结构示例:
[
{ client: "Client 1", project: "Project 1", item: "This is the first item." },
{ client: "Client 1", project: "Project 1", item: "This is the second item.", },
{ client: "Client 1", project: "Project 2", item: "This is the third item.", },
{ client: "Client 2", project: "Project 4", item: "This is the fourth item.", }
];
最好的方法是什么?另外,对于 API 设计有什么好的参考吗?