角 - 与$资源REST服务XML链接 [英] Angular - REST Service XML Links with $Resource

查看:115
本文介绍了角 - 与$资源REST服务XML链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的角度与SilverStripe我的后端。我使用这个模块 https://github.com/silverstripe/silverstripe-restfulserver 我的REST API而不是构建它自己。

在该API返回它看起来像

一个many_many关系的列表

 <配方HREF =HTTP://localhost/groceryList/api/v1/Recipe/2.x​​ml>
<标题>辣椒< /标题>
< ID> 2'; / ID>
<配料= LINKTYPEmany_manyHREF =HTTP://localhost/groceryList/api/v1/Recipe/2/Ingredients.xml>
    <质地HREF =HTTP://localhost/groceryList/api/v1/Ingredient/5.xmlID =5/>
    <质地HREF =HTTP://localhost/groceryList/api/v1/Ingredient/6.xmlID =6/>
    <质地HREF =HTTP://localhost/groceryList/api/v1/Ingredient/7.xmlID =7/>
< /成份及GT;
< /配方>

我的问题是2的一部分。


  1. 为什么配料的收集一堆的链接?我希望它会包含每种成分的名称。这是REST是怎么想工作?


  2. 采用了棱角分明$资源,怎么可以很容易地通过使用获得的成分,循环NG-重复?



解决方案

首先,你需要你的XML到JSON转换用的 HTTPS://$c$c.google.com/p/x2js/ 或的 https://github.com/johngeorgewright/angular-xml ,所以你需要一个HttpInterceptor所有的请求和响应转换服务器。

我不知道为什么你没有每种成分的名称到您的回复,我想,你需要改变你的API返回的响应,但我不知道该怎么SilverStripe的工作。

I am using Angular with SilverStripe for my backend. I am using this module https://github.com/silverstripe/silverstripe-restfulserver for my REST API instead of building it myself.

When the API returns a list with a many_many relationship it looks like

<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>

My question is 2 part.

  1. Why is the collection of ingredients a bunch of links? I was hoping it would contain the name of each ingredient. Is this how REST is suppose to work?

  2. Using Angular $Resource, how can easily get the ingredients to loop through using ng-repeat?

解决方案

First you need to convert your XML to JSON with https://code.google.com/p/x2js/ or https://github.com/johngeorgewright/angular-xml, so you need an HttpInterceptor to convert all your requests and responses from the server.

I don't know why you don't have the name of each ingredient into your response, I think you need to change the response returned by your API, but I don't know how SilverStripe work.

这篇关于角 - 与$资源REST服务XML链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆