javascript - Ember Restadapter 与 Jsonapiadapter 之间的区别

标签 javascript ember.js ember-data

Ember 使用 Restadapter 和 Jsonapiadapter 作为适配器。 就请求/响应的数据格式而言,两者之间的确切区别是什么? 使用这两个中的任何一个时我们需要确保的任何其他事情。

最佳答案

JSONAPIAdapter符合JSONApi规范

使用RESTAdapter当您有一个 JSON API,该 API 遵循具有复数对象名称的 REST 端点,并且具有使用返回的对象名称的根节点。

下面的例子:

JSONAPI 规范对象示例:

{
  "data": [{
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!"
    },
    "relationships": {
      "author": {
        "links": {
          "self": "http://example.com/articles/1/relationships/author",
          "related": "http://example.com/articles/1/author"
        },
        "data": { "type": "people", "id": "7" }
      }
    },
  }],
  "included": [{
    "type": "people",
    "id": "7",
    "attributes": {
      "name": "Dave",
      "twitter": "kiwiupover"
    }
  }]
} 

示例 Rest json api 对象:

{
  "posts": {
    "id": 5,
    "title": "An API that gets bikeshed for months ",
    "author": "kiwiupover",
    "comments": [1]
  },
  "comments": [{
    "id": 1,
    "name": "Dave",
  }]
}

Ember Data 提供了使 DS.adapter 适应特定 JSON API 形状的简单方法。

还有第三个adapter前面提到的适配器是从中扩展而来的。

关于javascript - Ember Restadapter 与 Jsonapiadapter 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52490540/

相关文章:

javascript - 一次将相同的 Prop 传递给子元素

javascript - 如何延迟计算属性以在 Ember.js 中重新计算它们自己?

javascript - 无法在 Therubyracer 中加载的 Ember 应用程序中加载商店

asp.net-mvc-4 - 如何使用 Ember .js 在 Web 应用程序中显示图像

ember.js - Ember 数据剩余适配器错误处理不起作用

ember.js - findAll 完成加载所有记录时的 Ember-Data 回调

javascript - Instafeed.js 带有加载更多选项

javascript - 如何查找函数中定义的变量

javascript - 重建从 localStorage 检索的对象函数

Ember.js:如何从 store.findRecord 调用访问 JSON API 元数据