来自 Mirage 的 Ember 数据无法显示在 index.hbs 上
Ember data from Mirage fails to display on index.hbs
余烬新手在这里。我一直在关注 Ember 网站上的教程 这里.
我一直在研究这个例子,一切正常......直到我尝试实施幻影。数据永远不会显示在 index.hbs 页面上。
这是我的模型钩子:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('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')
});
我的索引.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}}
最后是我的应用程序/幻影/配置.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:您的 Ember 应用程序尝试获取"http://localhost:4200/assets/vendor.js",但没有定义路由来处理此请求。在 mirage/config.js 文件中定义与此路径匹配的路由。您是否忘记添加命名空间?
和这个警告:
警告:在有效载荷中遇到"数据",但没有找到模型名称"datum"的模型(使用super-rentals@serializer:-rest:.modelNameFromPayloadKey("data"(解析模型名称(
但是,当我看到以下信息时,该信息似乎已成功检索:
成功请求:获取/租赁 对象 {data: Array[3]}
这反映了正确的数据。它只是在它和 index.hbs 之间打破了某个地方,我是新手来弄清楚的。我敢肯定这只是我的一个小误会。任何帮助将不胜感激!
您安装了错误版本的 Ember Data。此外,请确保在安装依赖项时重新启动服务器。
您收到的错误消息意味着您的应用程序正在使用 RESTAdapter(Ember Data 1.x 的默认适配器(。这就是为什么它查看顶级data
键并尝试单数化并找到相关模型的原因。
您可以按照最新 Ember CLI 发行版上的说明进行更新。或者,您可以npm install -g ember-cli@beta
从头开始。
- 从桌面读取python文件时高亮显示代码
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- Angular2:Index.html没有't显示该文件;正在加载&”;
- “index.swf”嵌入在“index.html”中,在一个页面中显示同一网站两次.HTML 标题标签/属性也显示值“
- 嵌套的 ng 重复显示错误的$index
- 来自 Mirage 的 Ember 数据无法显示在 index.hbs 上
- CSS Z-Index:如何在父级的兄弟姐妹上方显示元素?(并且有父母以上的表弟)
- 如何使用Python/Flask在heroku中显示index.html页面
- Angular:循环并显示从ng中的特定$index开始的所有值
- 按$index跟踪显示的结果太多
- 使用next按钮显示z-Index幻灯片
- 显示-inline-block与z-index和jquery
- 导航条显示在内容下面——z-index不工作
- 无法使用ng-hide指令在index.html中隐藏/显示导航条
- 背景图像在Firefox中显示,但在IE中不显示,可能是z-index问题
- 将所有请求重定向到index.php并在页面上显示URL
- AngularJS - 将$index显示为字符
- 查看器js只显示index.html
- 如何显示网站而不是ip/index.html
- 在index. js中显示多个(音乐)文件