Ember 来自 Mirage 的数据无法在 index.hbs 上显示

Ember data from Mirage fails to display on index.hbs

Ember新手看这里。我一直在关注 Ember 网站 here.

上的教程

我一直在研发这个词的示例并且一切正常...直到我尝试实施 Mirage。数据从未显示在 index.hbs 页面上。

这是我的模型挂钩:

import Ember from 'ember';

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

我的模特:rental.js

import DS from 'ember-data';
export default DS.Model.extend({
  title: DS.attr('string'),
  owner: DS.attr('string'),
  city: DS.attr('string'),
  type: DS.attr('string'),
  image: DS.attr('string'),
  bedrooms: DS.attr('number')
});

我的index.hbs:

<h1> Welcome to Super Rentals </h1>

We hope you find exactly what you're looking for in a place to stay.

{{#each model as |rentalUnit|}}
  {{rental-listing rental=rentalUnit}}
{{/each}}


{{#link-to "about"}}About{{/link-to}}
{{#link-to "contact"}}Click here to contact us.{{/link-to}}

最后是我的 app/mirage/config.js:

export default function() {
  this.get('/rentals', function() {
    return {
      data: [{
        type: 'rentals',
        id: 1,
        attributes: {
          title: 'Grand Old Mansion',
          owner: 'Veruca Salt',
          city: 'San Francisco',
          type: 'Estate',
          bedrooms: 15,
          image: 'https://upload.wikimedia.org/wikipedia/commons/c/cb/Crane_estate_(5).jpg'
        }
      }, {
        type: 'rentals',
        id: 2,
        attributes: {
          title: 'Urban Living',
          owner: 'Mike Teavee',
          city: 'Seattle',
          type: 'Condo',
          bedrooms: 1,
          image: 'https://upload.wikimedia.org/wikipedia/commons/0/0e/Alfonso_13_Highrise_Tegucigalpa.jpg'
        }
      }, {
        type: 'rentals',
        id: 3,
        attributes: {
          title: 'Downtown Charm',
          owner: 'Violet Beauregarde',
          city: 'Portland',
          type: 'Apartment',
          bedrooms: 3,
          image: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/Wheeldon_Apartment_Building_-_Portland_Oregon.jpg'
        }
      }]
    };
  });
}

我在 Chrome 开发人员控制台中收到两条消息:

Mirage: Your Ember app tried to GET 'http://localhost:4200/assets/vendor.js', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?

和这个警告:

WARNING: Encountered "data" in payload, but no model was found for model name "datum" (resolved model name using super-rentals@serializer:-rest:.modelNameFromPayloadKey("data"))

然而,我看到信息似乎已成功检索:

Successful request: GET /rentals Object {data: Array[3]}

反映了正确的数据。它只是在 index.hbs 和 index.hbs 之间的某个地方中断,我是新手想弄明白。我敢肯定这只是我的一个小误会。如有任何帮助,我们将不胜感激!

您安装的 Ember 数据版本错误。还要确保在安装依赖项时重新启动服务器。

您收到的错误消息表示您的应用程序正在使用 RESTAdapter(Ember 数据 1.x 的默认适配器)。这就是为什么它查看顶级 data 键并尝试单数化并找到相关模型的原因。

您可以按照 latest Ember CLI release 上的说明进行更新。或者,您可以 npm install -g ember-cli@beta 从头开始​​。