ember数据中单个请求的多个有效负载

时间:2016-05-10 07:23:49

标签: ember.js ember-data

我使用ember数据框架来处理api请求。有没有办法为单个api请求提供两个有效负载?

1 个答案:

答案 0 :(得分:0)

使用json-api,您可以包含相关类型,例如,请参阅here

HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "data": [{
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!",
      "body": "The shortest article. Ever.",
      "created": "2015-05-22T14:56:29.000Z",
      "updated": "2015-05-22T14:56:28.000Z"
    },
    "relationships": {
      "author": {
        "data": {"id": "42", "type": "people"}
      }
    }
  }],
  "included": [
    {
      "type": "people",
      "id": "42",
      "attributes": {
        "name": "John",
        "age": 80,
        "gender": "male"
      }
    }
  ]
}

在此示例中,您看到article有一个名为author的{​​{1}}类型的关系,然后在同一个有效负载中为people