【发布时间】:2015-03-01 21:30:16
【问题描述】:
我在后端使用 Angular 和 SilverStripe。我将这个模块 https://github.com/silverstripe/silverstripe-restfulserver 用于我的 REST API,而不是自己构建它。
当 API 返回一个具有 many_many 关系的列表时,它看起来像
<Recipe href="http://localhost/groceryList/api/v1/Recipe/2.xml">
<Title>Chilli</Title>
<ID>2</ID>
<Ingredients linktype="many_many" href="http://localhost/groceryList/api/v1/Recipe/2/Ingredients.xml">
<Ingredient href="http://localhost/groceryList/api/v1/Ingredient/5.xml" id="5"/>
<Ingredient href="http://localhost/groceryList/api/v1/Ingredient/6.xml" id="6"/>
<Ingredient href="http://localhost/groceryList/api/v1/Ingredient/7.xml" id="7"/>
</Ingredients>
</Recipe>
我的问题是 2 部分。
为什么成分的集合是一堆链接?我希望它会包含每种成分的名称。这就是 REST 的工作方式吗?
使用 Angular $Resource,如何使用 ng-repeat 轻松让成分循环通过?
【问题讨论】:
-
我会检查一下,谢谢你的链接。希望 colymbas 模块以更可用的格式返回 json。
-
一定要试试我的模块:github.com/colymba/silverstripe-restfulapi 如果您在使用它时遇到问题,请在 GitHub 上发布一些内容...
-
@colymba,我在周末试用了你的模块。到目前为止,对于我正在尝试做的事情来说,这似乎是一个更好的解决方案。如果我遇到问题或任何事情,我一定会在 github 上发布,谢谢。
标签: angularjs rest silverstripe