相关疑难解决方法(0)

没有JSON root的Ember.js REST适配器

Ember.js REST适配器期望JSON返回为:

{
    "person": {
        "first_name": "Barack",
        "last_name": "Obama",
        "is_person_of_the_year": true
    }
}
Run Code Online (Sandbox Code Playgroud)

但我的API返回没有根元素的数据:

{
    "first_name": "Barack",
    "last_name": "Obama",
    "is_person_of_the_year": true
}
Run Code Online (Sandbox Code Playgroud)

是否可以自定义REST适配器以使其接受我的JSON数据?现在它显示" 断言失败:你的服务器返回一个带有键0的哈希,但你没有映射它 "

更新: 基于Sherwin Yu的回答,这是我想出的,似乎到目前为止工作:https://gist.github.com/richardkall/5910875

javascript api json ember.js ember-data

7
推荐指数
2
解决办法
7622
查看次数

标签 统计

api ×1

ember-data ×1

ember.js ×1

javascript ×1

json ×1