Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Angular-REST服务XML链接与$Resource_Angularjs_Rest_Silverstripe - Fatal编程技术网

Angularjs Angular-REST服务XML链接与$Resource

Angularjs Angular-REST服务XML链接与$Resource,angularjs,rest,silverstripe,Angularjs,Rest,Silverstripe,我使用Angular和SilverStripe作为后端。我将这个模块用于RESTAPI,而不是自己构建它 当API返回一个具有多个关系的列表时,它看起来像 <Recipe href="http://localhost/groceryList/api/v1/Recipe/2.xml"> <Title>Chilli</Title> <ID>2</ID> <Ingredients linktype="many_many" href="h

我使用Angular和SilverStripe作为后端。我将这个模块用于RESTAPI,而不是自己构建它

当API返回一个具有多个关系的列表时,它看起来像

<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轻松地使配料循环


  • 首先,您需要使用or将XML转换为JSON,因此您需要一个HttpInterceptor来转换来自服务器的所有请求和响应


    我不知道为什么您的响应中没有每个成分的名称,我认为您需要更改API返回的响应,但我不知道SilverStripe是如何工作的。

    我可以非常轻松地将响应转换为json,所以这不会是一个问题。更改响应可能是最好的解决方案。我想这样做,但我不明白为什么最初的开发人员会这样编程。我会等待其他答案,但如果更改响应是最好的方式,我会接受你的答案。可能是因为它们是使用API的其他应用程序?如果API可以接收和响应JSON,那么与AngularJS一起使用会更容易。许多旧服务仍然使用SOAP和XML,主要原因是它们与其他服务互操作。我建议大家看看下面的回购协议:我会去看看,谢谢链接。希望colymbas模块能以更有用的格式返回json。一定要试试我的模块:如果你在使用它时遇到问题,在GitHub上发布一些东西…@colymba,我在周末试用了你的模块。到目前为止,这似乎是一个更好的解决方案,我正在尝试做的。如果我遇到问题或任何事情,我一定会在github上发布,谢谢。