应用程序/模型/ index.js
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default Model.extend({
title: attr(),
owner: attr(),
city: attr(),
type: attr(),
image: attr(),
bedrooms: attr()
});
应用程序/模板/ index.hbs
{{#each model as |rental|}}
<p>Location: {{rental.city}}</p>
<p>Number of bedrooms: {{rental.bedrooms}}</p>
{{/each}}
我从sinatra返回这个/租赁数据请求
{ data: [{
id: 1,
title: 'Grand Old Mansion',
owner: 'Veruca Salt',
city: 'San Francisco',
bedrooms: 15,
type: 'rental',
image: 'https://upload.wikimedia.org/wikipedia/commons/c/cb/Crane_estate_(5).jpg'
}, {
id: 2,
title: 'Urban Living',
owner: 'Mike TV',
city: 'Seattle',
bedrooms: 1,
type: 'rental',
image: 'https://upload.wikimedia.org/wikipedia/commons/0/0e/Alfonso_13_Highrise_T egucigalpa.jpg'
}, {
id: 3,
title: 'Downtown Charm',
owner: 'Violet Beauregarde',
city: 'Portland',
bedrooms: 3,
type: 'rental',
image: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/Wheeldon_Apartment_Bu ilding_-_Portland_Oregon.jpg'
}, {
id: 4,
title: 'xDowntown Charm',
owner: 'Violet Beauregarde',
city: 'Portland',
bedrooms: 3,
type: 'rental',
image: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/Wheeldon_Apartment_Building_-_Portland_Oregon.jpg'
}]}.to_json
每个循环都知道有多少条记录,但是当浏览器显示
时,字段数据丢失了Location:
Number of bedrooms:
Location:
Number of bedrooms:
Location:
Number of bedrooms:
Location:
Number of bedrooms:
使用ember 2.5
答案 0 :(得分:1)
每个评论由dynamic_cast我将JSON结构更改为此并使其工作。
{
"data" => [{
"type" => "rentals",
"id" => "1",
"attributes" => {
"title" => 'Grand Old Mansion',
"owner" => 'Veruca Salt',
"city" => 'San Francisco',
"bedrooms" => 15,
"type" => 'rental',
"image" => 'https://upload.wikimedia.org/wikipedia/commons/c/cb/Crane_estate_(5).jpg'
}
},
{
"type" => "rentals",
"id" => "2",
"attributes" => {
"title" => 'Urban Living',
"owner" => 'Mike TV',
"city" => 'Seattle',
"bedrooms" => 1,
"type" => 'rental',
"image" => 'https://upload.wikimedia.org/wikipedia/commons/0/0e/Alfonso_13_Highrise_T egucigalpa.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'
}
}
]
}.to_json