我試圖從我的Rails API中獲取一些數據並將其顯示在模板中。 我很嶄新,因此如果這是一個非常愚蠢的問題,那麼解釋越簡單越好,原諒我。Ember數據沒有填充模型
問題似乎是api數據沒有正確地到達模型,它在我有靜態夾具數據但不適用於服務器數據時有效。對服務器的Get請求正在進行,我得到了很好的響應,所以json如何移動到模型中肯定有問題。
我在routes/external/jobs.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('job');
}
})路線;
我的工作模型models/job.js
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string'),
id: DS.attr('string')
});
我期待我的API的形式返回數據
{
"jobs": [
{
id: "jfdsa132113",
title: "developer",
type: "Job",
body: "lorem ipsum",
published_at: date,
tags: [
"some stuff",
"more stuff"
]
},
{
id: "fdsafd3432",
title: "designer",
type: "Job",
body: "lorem ipsum",
published_at: date,
tags: [
"some stuff",
"more stuff"
]
}
]
}
我的路由器
Router.map(function() {
//index route
this.route('external', function() {
this.route('jobs');
this.route('support');
});
export default Router;
嘿旁註,目前的語法是'{{#each model as | job |}}''。 – locks
感謝您的提醒。我更新了它,不是問題,雖然 – chesapeake4