Angular - REST 服务 XML 与 $Resource 的链接
Angular - REST Service XML Links with $Resource
我正在使用 Angular 和 SilverStripe 作为我的后端。我将此模块 https://github.com/silverstripe/silverstripe-restfulserver 用于我的 REST API 而不是自己构建它。
当 API returns 具有 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>
我的问题分为两部分。
为什么食材合集是一堆链接?我希望它包含每种成分的名称。这就是 REST 的工作方式吗?
使用 Angular $Resource,如何轻松地使用 ng-repeat 循环获取成分?
首先,您需要使用 https://code.google.com/p/x2js/ or https://github.com/johngeorgewright/angular-xml 将 XML 转换为 JSON,因此您需要一个 HttpInterceptor 来转换来自服务器的所有请求和响应。
我不知道为什么您的回复中没有每种成分的名称,我认为您需要更改 API 返回的回复,但我不知道 SilverStripe 如何工作。
我正在使用 Angular 和 SilverStripe 作为我的后端。我将此模块 https://github.com/silverstripe/silverstripe-restfulserver 用于我的 REST API 而不是自己构建它。
当 API returns 具有 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>
我的问题分为两部分。
为什么食材合集是一堆链接?我希望它包含每种成分的名称。这就是 REST 的工作方式吗?
使用 Angular $Resource,如何轻松地使用 ng-repeat 循环获取成分?
首先,您需要使用 https://code.google.com/p/x2js/ or https://github.com/johngeorgewright/angular-xml 将 XML 转换为 JSON,因此您需要一个 HttpInterceptor 来转换来自服务器的所有请求和响应。
我不知道为什么您的回复中没有每种成分的名称,我认为您需要更改 API 返回的回复,但我不知道 SilverStripe 如何工作。