ember.js - Ember model not displaying field data in template -
app/models/index.js
import model 'ember-data/model'; import attr 'ember-data/attr'; export default model.extend({ title: attr(), owner: attr(), city: attr(), type: attr(), image: attr(), bedrooms: attr() });
app/template/index.hbs
{{#each model |rental|}} <p>location: {{rental.city}}</p> <p>number of bedrooms: {{rental.bedrooms}}</p> {{/each}}
am returning sinatra /rentals data request
{ 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
the each loop knows how many records there field data missing browser shows this
location: number of bedrooms: location: number of bedrooms: location: number of bedrooms: location: number of bedrooms:
using ember 2.5
per comment dynamic_cast changed json structure , got work.
{ "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
Comments
Post a Comment