Ember 数据 - 未加载相关记录

Ember data - Associated records were not loaded

我尝试加载模拟 Json,但我收到以下错误:

未捕获错误:断言失败:您在 ID 为 2 的 'post' 上查找了 'author' 关系,但未加载某些关联记录。确保它们都与父记录一起加载,或者指定关系是异步的 (DS.belongsTo({ async: true }))

这是来自 http://localhost:4200/api/posts/2

的 JSON
{  
   "post":{  
      "id":2,
      "title":"Monkeys",
      "date":"2013-12-21T00:04:20.461Z",
      "author":1,
      "body":"Vestibulum porttitor leo maximustae ultricies risus efficitur sit amet."
   },
   "author":{  
      "id":1,
      "name":"George",
      "posts":[  
         2
      ]
   }
}

models/post.js

import DS from 'ember-data';

export default DS.Model.extend({
    title: DS.attr('string'),
    body: DS.attr('string'),
    date: DS.attr('date'),
    author: DS.belongsTo('author')
});

models/author.js

import DS from 'ember-data';

export default DS.Model.extend({
    name: DS.attr('string'),
    posts: DS.hasMany('post')
});

你试过像这样嘲笑你的json吗?

{  
   "posts":[
       {  
          "id":2,
          "title":"Monkeys",
          "date":"2013-12-21T00:04:20.461Z",
          "author":1,
          "body":"Vestibulum porttitor leo maximustae ultricies risus efficitur sit amet."
       }
   ],
   "author":{  
      "id":1,
      "name":"George",
      "posts":[  
         2
      ]
   }
}

错误状态 some of the associated records were not loaded