试图用ember和django休息框架获取数据

时间:2016-07-18 20:58:51

标签: ember.js django-rest-framework

我已经安装了Ember Django Adapter(EDA),我已经按照教程和模板中的所有内容都可以,但我没有从我的API获取数据...但是当我的模型连接到api时,我得到了在控制台中跟随警告。

WARNING: Encountered "articles" in payload, but no model was found for model name "article" (resolved model name using frontend@serializer:articles:.modelNameFromPayloadKey("articles"))

这是我的代码:

  

应用程序/应用/ serializer.js

import DRFSerializer from '../serializers/drf';

export default DRFSerializer.extend({
});
  

应用程序/应用/ adapter.js

import DRFAdapter from '../adapters/drf';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';

export default DRFAdapter.extend(DataAdapterMixin , {
  authorizer: 'authorizer:django'
});
  

应用程序/ router.js

import Ember from 'ember';
import config from './config/environment'; 

const Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() { 
  this.route('index'); 
});

export default Router;
  

应用程序/模型/ articles.js

import Model from 'ember-data/model';
import attr from 'ember-data/attr';

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

应用程序/索引/ route.js

import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return this.get('store').findAll('articles'); 
  }
});
  

应用程序/索引/ template.hbs

{{#each model as |article|}}
    <article class="listing">
      <h3>{{article.title}}</h3>
    </article>
{{/each}}

1 个答案:

答案 0 :(得分:1)

在命名模型时应使用单数词,因此将模型文件更改为“article.js”,并将route.js文件更改为this.get('store').findAll('article');