emberjs 2 connect to an api flask - Encountered a resource object with an undefined type

僤鯓⒐⒋嵵緔 提交于 2019-12-04 02:54:22

Option 1 - Using JSONAPIAdapter

Out of the box Ember.js expects responses from server in JSONApi standard. You can see this standard here: http://jsonapi.org/

When you use JSONAPIAdapter, your server response should look like this:

{
  "data": [
    {
      "type": "trademarks",
      "id": "1",
      "attributes": {
        "expediente": "1717801",
        "fecha_de_presentacion": "01/02/2016 12:00:00 AM",
        "figura_juridica": "REGISTRO DE MARCA",
        "logotipo": null,
        "signo": "IGUY",
        "tipo": "NOMINATIVA",
        "titular": "SAMSONITE IP HOLDINGS S.\u00c0.R.L."
      }
    },
    {
     "type": "trademarks",
      "id": "2",
      "attributes": {
        "expediente": "1717793",
        "fecha_de_presentacion": "01/02/2016 12:00:00 AM",
        "figura_juridica": "REGISTRO DE MARCA",
        "logotipo": "1_files/direct_151.gif",
        "signo": "URGOSTART",
        "tipo": "MIXTA",
        "titular": "HCP HEALTHCARE ASIA PTE. LTD"
      }
    },
    .
    . rest of the data
    .
    ]
}

You can use a few external package which helps generate jsonAPI standard payload from flask: https://github.com/vertical-knowledge/ripozo/, https://github.com/benediktschmitt/py-jsonapi, https://github.com/xamoom/xamoom-janus

Option 2 - Using RESTAdapter

http://emberjs.com/api/data/classes/DS.RESTAdapter.html

You can change your adapter with rewriting export default DS.JSONAPIAdapter.extend to export default DS.RESTAdapter.extend in /app/adapters/application.js.

In this case, your server payload should look like this:

{
  "trademarks": [
    {
      "id": "1"
      "expediente": "1717801",
      "fecha_de_presentacion": "01/02/2016 12:00:00 AM",
      "figura_juridica": "REGISTRO DE MARCA",
      "logotipo": null,
      "signo": "IGUY",
      "tipo": "NOMINATIVA",
      "titular": "SAMSONITE IP HOLDINGS S.\u00c0.R.L."
    },
    {
      "id": "2"
      "expediente": "1717793",
      "fecha_de_presentacion": "01/02/2016 12:00:00 AM",
      "figura_juridica": "REGISTRO DE MARCA",
      "logotipo": "1_files/direct_151.gif",
      "signo": "URGOSTART",
      "tipo": "MIXTA",
      "titular": "HCP HEALTHCARE ASIA PTE. LTD"
    },
    .
    .
    .
    ]
}

If you are learning Ember.js, I wrote a free tutorial about the latest Ember, maybe it could help also: Ember.js tutorial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!